anki/ts/editor/change-timer.ts
2021-09-15 13:45:19 +02:00

19 lines
465 B
TypeScript

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
export class ChangeTimer {
private value: number | null = null;
schedule(action: () => void, delay: number): void {
this.clear();
this.value = setTimeout(action, delay);
}
clear(): void {
if (this.value) {
clearTimeout(this.value);
this.value = null;
}
}
}