summaryrefslogtreecommitdiff
path: root/node_modules/@jet/environment/util/expiring-value.js
blob: a5ac55712141c74e09e9c4f26fdeecabbc50f61c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpiringValue = void 0;
/**
 * A class that wraps some value that expires in some future time.
 */
class ExpiringValue {
    constructor(value, maxAge) {
        this._value = value;
        this._maxAge = maxAge;
    }
    /// Whether or not value is valid (not expired).
    isValid() {
        return Date.now() < this._maxAge;
    }
    /** Access the expiring value, returning null if it is expired. */
    get value() {
        return this.isValid() ? this._value : null;
    }
}
exports.ExpiringValue = ExpiringValue;
//# sourceMappingURL=expiring-value.js.map