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
This commit is contained in:
Andrey Lushnikov 2021-03-18 09:29:37 -07:00 committed by GitHub
parent dfb1c99ad1
commit 9a50304dc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;