shardy
Version:
Framework for online games and applications on Node.js
29 lines • 793 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Pulse = void 0;
const Commander_1 = require("./Commander");
class Pulse {
constructor(mode) {
this.mode = mode;
this.onPulse = () => { };
this.checks = 0;
this.timer = setInterval(() => this.onCheckPulse(), process.env.PULSE_INTERVAL);
this.limit = this.mode === Commander_1.CommanderMode.Bot ? 1 : process.env.PULSE_LIMIT;
}
onCheckPulse() {
this.checks++;
if (this.checks > this.limit) {
this.reset();
this.onPulse();
}
}
reset() {
this.checks = 0;
}
clear() {
this.reset();
clearInterval(this.timer);
}
}
exports.Pulse = Pulse;
//# sourceMappingURL=Pulse.js.map