mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
Make CooldownTimer accept an aync action
This commit is contained in:
parent
6cab377083
commit
224ea3abb1
2 changed files with 4 additions and 5 deletions
|
|
@ -47,7 +47,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
const debouncer = new CooldownTimer(500);
|
||||
|
||||
$: debouncer.schedule(() => {
|
||||
$: debouncer.schedule(async () => {
|
||||
const cache = getCache($pageTheme.isDark, fontSize);
|
||||
const entry = cache.get(mathjax);
|
||||
if (entry) {
|
||||
|
|
|
|||
|
|
@ -3,20 +3,19 @@
|
|||
|
||||
export class CooldownTimer {
|
||||
private executing = false;
|
||||
private queuedAction: (() => void) | null = null;
|
||||
private queuedAction: (() => Promise<void>) | null = null;
|
||||
private delay: number;
|
||||
|
||||
constructor(delayMs: number) {
|
||||
this.delay = delayMs;
|
||||
}
|
||||
|
||||
schedule(action: () => void): void {
|
||||
schedule(action: () => Promise<void>): void {
|
||||
if (this.executing) {
|
||||
this.queuedAction = action;
|
||||
} else {
|
||||
this.executing = true;
|
||||
action();
|
||||
setTimeout(this.#pop.bind(this), this.delay);
|
||||
action().then(() => setTimeout(this.#pop.bind(this), this.delay));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue