deasync icon indicating copy to clipboard operation
deasync copied to clipboard

Not working with promises in Electron

Open NotWearingPants opened this issue 4 years ago • 1 comments

Reproduction:

  1. Follow Electron's quick start guide to get a working electron app running (packaging not needed)
  2. npm install deasync
  3. 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);
    
  4. 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

NotWearingPants avatar Nov 15 '20 22:11 NotWearingPants

+1

tiitremmel avatar Mar 15 '23 10:03 tiitremmel