添加站内消息,修复讨论节点丢失的问题

This commit is contained in:
undefined committed 2020-05-03 15:33:54 +08:00
1 parent 33e277f28f
commit 627e64a901
44 files changed
+582 -540

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
class Cron {
constructor() {
this.tasks = [];
}
plan(time, task) {
const now = new Date();
if (!(time instanceof Date)) time = new Date(time);
this.tasks.push({
id: setTimeout(() => {
for (const i in this.tasks) {
if (this.tasks[i].func === task) {
this.tasks.splice(i, 1);
break;
}
}
task();
}, time - now),
func: task,
});
}
interval(time, task) {
const now = new Date();
if (!(time instanceof Date)) time = new Date(time);
this.tasks.push({
id: setTimeout(() => { task(); }, time - now),
func: task,
});
}
}
module.exports = Cron;