anki/ts/editor/change-timer.ts

19 lines
465 B
TypeScript
Raw Normal View History

2021-04-13 10:57:08 +02:00
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
2021-02-09 04:38:04 +01:00
export class ChangeTimer {
private value: number | null = null;
2021-08-07 23:38:21 +02:00
schedule(action: () => void, delay: number): void {
this.clear();
this.value = setTimeout(action, delay);
}
2021-08-07 23:38:21 +02:00
clear(): void {
if (this.value) {
clearTimeout(this.value);
this.value = null;
}
}
}