2021-08-22 20:20:49 +00:00
|
|
|
const logger = require("./logger.js");
|
2021-05-17 22:35:18 +00:00
|
|
|
|
|
|
|
const timerTable = {};
|
|
|
|
|
|
|
|
function getTable() {
|
|
|
|
return timerTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
function add(identifier, callback, delay) {
|
|
|
|
if (timerTable[identifier] != null) {
|
|
|
|
clearInterval(timerTable[identifier]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function wrapper() {
|
|
|
|
try {
|
|
|
|
callback();
|
|
|
|
} catch (error) {
|
|
|
|
logger.error("hf:timer", `Timer "${identifier}" failed: ${error}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
timerTable[identifier] = setInterval(wrapper, delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove(identifier) {
|
|
|
|
if (timerTable[identifier] != null) {
|
|
|
|
clearInterval(timerTable[identifier]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getTable,
|
|
|
|
add,
|
|
|
|
remove,
|
|
|
|
};
|