From deee6f5a4b61d9f09640379196b62672b5c695d9 Mon Sep 17 00:00:00 2001 From: Bryan Jensen Date: Wed, 1 Nov 2023 14:20:25 -0700 Subject: [PATCH] Always grab current setImmediate in queueTask --- src/lib/scheduling.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib/scheduling.ts b/src/lib/scheduling.ts index 6d960f7c..d2190438 100644 --- a/src/lib/scheduling.ts +++ b/src/lib/scheduling.ts @@ -23,7 +23,10 @@ function getSetImmediateFromJsdom() { // transactions are marked as not active when the event loop runs. The next // tick queue and microtask queue run within the current event loop macrotask, // so they'd process database operations too quickly. -export const queueTask: (fn: () => void) => void = - globalThis.setImmediate || - getSetImmediateFromJsdom() || - ((fn: () => void) => setTimeout(fn, 0)); +export const queueTask = (fn: () => void): void => { + const setImmediate = + globalThis.setImmediate || + getSetImmediateFromJsdom() || + ((fn: () => void) => setTimeout(fn, 0)); + setImmediate(fn); +};