UNPKG

@cimo/pid

Version:

Process id. Light, fast and secure.

62 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Manager { mainObject; timeCheck; interval = () => { setInterval(() => { const dateNow = Date.now(); for (const key in this.mainObject) { const { timeCreated, timeLimit } = this.mainObject[key]; const difference = dateNow - timeCreated; if (difference > timeLimit && timeLimit > 0) { this.remove(Number(key)); break; } } }, this.timeCheck); }; constructor(timeCheckValue = 25000) { this.mainObject = {}; this.timeCheck = timeCheckValue; this.interval(); } getMainObject = () => { return this.mainObject; }; checkRunning = (tagValue) => { for (const key in this.mainObject) { if (this.mainObject[key].tag === tagValue) { return true; } } return false; }; add = (tag, data, timeLimit, callback) => { const isRunning = this.checkRunning(tag); let key = -1; if (!isRunning) { key = Object.keys(this.mainObject).length + 1; this.mainObject[key] = { tag, data, timeLimit, timeCreated: Date.now() }; } callback(isRunning, key); }; update = (key, data) => { if (this.mainObject[key]) { const object = this.mainObject[key]; this.mainObject[key] = { tag: object.tag, data, timeLimit: object.timeLimit, timeCreated: object.timeCreated }; } }; remove = (key) => { if (this.mainObject[key]) { delete this.mainObject[key]; } }; } exports.default = Manager; //# sourceMappingURL=Manager.js.map