|
|
@@ -2,6 +2,7 @@ type Subscriber = {
|
|
|
lastTick: number;
|
|
|
seconds: number;
|
|
|
tick: (() => void) | Promise<void>;
|
|
|
+ queued?: boolean;
|
|
|
};
|
|
|
|
|
|
export class Timer {
|
|
|
@@ -31,7 +32,8 @@ export class Timer {
|
|
|
private loop() {
|
|
|
const now = new Date();
|
|
|
Object.values(this.subscribers).forEach(sub => {
|
|
|
- if (now.getTime() >= sub.lastTick + sub.seconds * 1000) {
|
|
|
+ if (!sub.queued && now.getTime() >= sub.lastTick + sub.seconds * 1000) {
|
|
|
+ sub.queued = true;
|
|
|
this.queue.push(sub);
|
|
|
}
|
|
|
});
|
|
|
@@ -48,6 +50,7 @@ export class Timer {
|
|
|
} else {
|
|
|
await sub.tick;
|
|
|
}
|
|
|
+ sub.queued = false;
|
|
|
}
|
|
|
}
|
|
|
|