From 9a50304dc114acde02c4385f7c2989b4399c6381 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 18 Mar 2021 09:29:37 -0700 Subject: [PATCH] fix: work-around electron's broken event loop (#5867) Since `setImmediate` doesn't create a new task in Electron, we have to fallback to `setTimeout` instead. See https://github.com/electron/electron/issues/28261 for details. Fixes #5228 --- src/utils/utils.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 529660f0bc..f97a5556c9 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -24,6 +24,11 @@ const mkdirAsync = util.promisify(fs.mkdir.bind(fs)); // See https://joel.tools/microtasks/ export function makeWaitForNextTask() { + // As of Mar 2021, Electorn v12 doesn't create new task with `setImmediate` despite + // using Node 14 internally, so we fallback to `setTimeout(0)` instead. + // @see https://github.com/electron/electron/issues/28261 + if (process.versions.electron) + return (callback: () => void) => setTimeout(callback, 0); if (parseInt(process.versions.node, 10) >= 11) return setImmediate;