From 224ea3abb126f8c50085a291ea9f4f8f704443b8 Mon Sep 17 00:00:00 2001 From: Abdo Date: Sun, 19 Oct 2025 06:10:23 +0300 Subject: [PATCH] Make CooldownTimer accept an aync action --- ts/lib/editable/Mathjax.svelte | 2 +- ts/lib/editable/cooldown-timer.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ts/lib/editable/Mathjax.svelte b/ts/lib/editable/Mathjax.svelte index 202ca56e2..b32d0cc09 100644 --- a/ts/lib/editable/Mathjax.svelte +++ b/ts/lib/editable/Mathjax.svelte @@ -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) { diff --git a/ts/lib/editable/cooldown-timer.ts b/ts/lib/editable/cooldown-timer.ts index 892e2b05f..cd0dd78f6 100644 --- a/ts/lib/editable/cooldown-timer.ts +++ b/ts/lib/editable/cooldown-timer.ts @@ -3,20 +3,19 @@ export class CooldownTimer { private executing = false; - private queuedAction: (() => void) | null = null; + private queuedAction: (() => Promise) | null = null; private delay: number; constructor(delayMs: number) { this.delay = delayMs; } - schedule(action: () => void): void { + schedule(action: () => Promise): 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)); } }