pandora-metrics
Version:
## Overview
28 lines • 820 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const MetricType_1 = require("../common/MetricType");
class CachedGauge {
constructor(timeout) {
this.type = MetricType_1.MetricType.GAUGE;
this.proxyMethod = [];
this.reloadAt = Date.now();
this.timeout = timeout || CachedGauge.DEFAULT_TIMEOUT;
}
getValue() {
if (this.shouldLoad()) {
this.value = this.loadValue();
}
return this.value;
}
shouldLoad() {
let current = Date.now();
if (current - this.reloadAt > this.timeout) {
this.reloadAt = current;
return true;
}
return false;
}
}
CachedGauge.DEFAULT_TIMEOUT = 5000;
exports.CachedGauge = CachedGauge;
//# sourceMappingURL=CachedGauge.js.map