22 lines
444 B
TypeScript
22 lines
444 B
TypeScript
export class AutosaveScheduler {
|
|
private timer: number | null = null;
|
|
|
|
schedule(callback: () => void | Promise<void>, delayMs = 1500): void {
|
|
this.cancel();
|
|
this.timer = window.setTimeout(() => {
|
|
this.timer = null;
|
|
void callback();
|
|
}, delayMs);
|
|
}
|
|
|
|
cancel(): void {
|
|
if (this.timer === null) return;
|
|
window.clearTimeout(this.timer);
|
|
this.timer = null;
|
|
}
|
|
|
|
dispose(): void {
|
|
this.cancel();
|
|
}
|
|
}
|