Files
gridpilot.gg/apps/website/lib/blockers/ThrottleBlocker.ts
2025-12-23 23:36:55 +01:00

26 lines
560 B
TypeScript

import { Blocker } from './Blocker';
/**
* ThrottleBlocker enforces a minimum time delay between executions.
*
* Useful for preventing rapid successive actions, such as button mashing.
*/
export class ThrottleBlocker extends Blocker {
private lastExecutionTime = 0;
constructor(private readonly delayMs: number) {
super();
}
canExecute(): boolean {
return Date.now() - this.lastExecutionTime >= this.delayMs;
}
block(): void {
this.lastExecutionTime = Date.now();
}
release(): void {
// No-op for throttle blocker
}
}