This commit is contained in:
2025-12-18 14:26:17 +01:00
parent 61f675d991
commit bf1f09c774
9 changed files with 387 additions and 30 deletions

View File

@@ -0,0 +1,24 @@
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) {}
canExecute(): boolean {
return Date.now() - this.lastExecutionTime >= this.delayMs;
}
block(): void {
this.lastExecutionTime = Date.now();
}
release(): void {
// No-op for throttle blocker
}
}