Skip to content

Commit

Permalink
Fix RateLimiter.
Browse files Browse the repository at this point in the history
  • Loading branch information
gebner committed May 9, 2024
1 parent f37e526 commit 29afd2d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions server/src/signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,20 @@ export class RateLimiter implements SignalProc {
if (this.timeout) {
this.missedFire = true;
} else {
this.timeout = setTimeout(() => {
this.timeout = undefined;
if (this.missedFire) {
this.missedFire = false;
this.handler();
}
}, this.millis);
this.setTimeout();
// Run async
setTimeout(() => this.handler());
}
}

private setTimeout() {
this.timeout = setTimeout(() => {
this.timeout = undefined;
if (this.missedFire) {
this.missedFire = false;
this.setTimeout();
this.handler();
}
}, this.millis);
}
}

0 comments on commit 29afd2d

Please sign in to comment.