Skip to content

Commit

Permalink
fix: work-around electron's broken event loop (#5867)
Browse files Browse the repository at this point in the history
Since `setImmediate` doesn't create a new task in Electron,
we have to fallback to `setTimeout` instead.

See electron/electron#28261 for details.

Fixes #5228
  • Loading branch information
aslushnikov committed Mar 18, 2021
1 parent dfb1c99 commit 9a50304
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 9a50304

Please sign in to comment.