deasync
deasync copied to clipboard
Not working with promises in Electron
Reproduction:
- Follow Electron's quick start guide to get a working electron app running (packaging not needed)
-
npm install deasync
- Paste the following into the devtools in the Electron window:
const deasync = require('deasync'); let done = false; Promise.resolve().then(() => { done = true; }); deasync.loopWhile(() => !done);
- The window will hang in an infinite loop
The problem seems to be that there are 3 competing event loops here: Node.js (libuv), Chrome, and V8 (for Promises).
In Node.js the Promise event loop is ran inside the libuv event loop, which means deasync
runs everything when it runs the libuv loop.
And according to logic and this blogpost, in Electron the Chrome event loop is the main one, under it there is the V8 event loop and libuv event loop. Therefore running the libuv loop won't run promises.
This issue is different than #47 #64 #81 #95 because deasync is working (e.g. with sleep), but not with promises or any DOM asynchronous stuff, because of the event loop problems mentioned above.
Current versions: Electron 10.1.5 Node.js 12.16.3 V8 8.5.210.26 Chrome 85.0.4183.121
+1