0

Does wrapping a blocking operation inside a promise still block the event loop? For example if I wrap a blocking syscall in a promise and return a resolve() when the blocking syscall ends does it keep the event loop running?

let a = new Promise((resolve, reject) => {
    // run blocking synchronous function here
    resolve();
}).then() {
    // continue after promise solved
}

// running a periodic 'blinker'
setInterval(() => {
    console.log('another second has passed');
}, 1000)

Would messages keep popping up every second if that blocking call took longer than that?

  • Does this answer your question? https://stackoverflow.com/questions/39988890/do-javascript-promises-block-the-stack – dwosk Oct 04 '20 at 17:23
  • When I read it before the main topics didn't seem to answer that, but I found this "CPU intensive logic will block the event loop regardless of any wrapping promises.". So I guess that blocking operation would still block the event loop... anyway thanks! –  Oct 04 '20 at 17:27

0 Answers0