Skip to content

Commit

Permalink
Merge pull request #93 from bryan-codaio/fix-cached-set-immediate
Browse files Browse the repository at this point in the history
Always grab current setImmediate in queueTask
  • Loading branch information
dumbmatter authored May 20, 2024
2 parents 5bf419c + deee6f5 commit f0c1e0f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib/scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit f0c1e0f

Please sign in to comment.