mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 20:57:13 -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);
|
const debouncer = new CooldownTimer(500);
|
||||||
|
|
||||||
$: debouncer.schedule(() => {
|
$: debouncer.schedule(async () => {
|
||||||
const cache = getCache($pageTheme.isDark, fontSize);
|
const cache = getCache($pageTheme.isDark, fontSize);
|
||||||
const entry = cache.get(mathjax);
|
const entry = cache.get(mathjax);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,19 @@
|
||||||
|
|
||||||
export class CooldownTimer {
|
export class CooldownTimer {
|
||||||
private executing = false;
|
private executing = false;
|
||||||
private queuedAction: (() => void) | null = null;
|
private queuedAction: (() => Promise<void>) | null = null;
|
||||||
private delay: number;
|
private delay: number;
|
||||||
|
|
||||||
constructor(delayMs: number) {
|
constructor(delayMs: number) {
|
||||||
this.delay = delayMs;
|
this.delay = delayMs;
|
||||||
}
|
}
|
||||||
|
|
||||||
schedule(action: () => void): void {
|
schedule(action: () => Promise<void>): void {
|
||||||
if (this.executing) {
|
if (this.executing) {
|
||||||
this.queuedAction = action;
|
this.queuedAction = action;
|
||||||
} else {
|
} else {
|
||||||
this.executing = true;
|
this.executing = true;
|
||||||
action();
|
action().then(() => setTimeout(this.#pop.bind(this), this.delay));
|
||||||
setTimeout(this.#pop.bind(this), this.delay);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue