57 lines
3.3 KiB
JavaScript
57 lines
3.3 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Interval = void 0;
|
|
const plugins = __importStar(require("./smarttime.plugins"));
|
|
class Interval {
|
|
constructor(intervalMillisencondsArg) {
|
|
this.status = 'initial';
|
|
this.statusAuthorization = null;
|
|
this.intervalJobs = [];
|
|
this.intervalMilliseconds = intervalMillisencondsArg;
|
|
}
|
|
start() {
|
|
this.status = 'started';
|
|
const statusAuth = new Date();
|
|
this.statusAuthorization = statusAuth;
|
|
const runInterval = async () => {
|
|
while (this.status === 'started' && this.statusAuthorization === statusAuth) {
|
|
await plugins.smartdelay.delayFor(this.intervalMilliseconds);
|
|
this.executeIntervalJobs();
|
|
}
|
|
};
|
|
runInterval();
|
|
}
|
|
stop() {
|
|
this.status = 'stopped';
|
|
this.statusAuthorization = null;
|
|
}
|
|
addIntervalJob(funcArg) {
|
|
this.intervalJobs.push(funcArg);
|
|
}
|
|
executeIntervalJobs() {
|
|
for (const funcArg of this.intervalJobs) {
|
|
funcArg();
|
|
}
|
|
}
|
|
}
|
|
exports.Interval = Interval;
|
|
//# s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