mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
添加站内消息,修复讨论节点丢失的问题
This commit is contained in:
1 parent
33e277f28f
commit
627e64a901
44 files changed
+582
-540
No files matched your search
@@ -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;
|
||||
Reference in new issue
Block a user