Do Javascript promises block the stack

后端 未结 4 1669
伪装坚强ぢ
伪装坚强ぢ 2020-12-18 01:11

When using Javascript promises, does the event loop get blocked?

My understanding is that using await & async, makes the stack stop until the operation has comp

4条回答
  •  盖世英雄少女心
    2020-12-18 02:04

    An await blocks only the current async function, the event loop continues to run normally. When the promise settles, the execution of the function body is resumed where it stopped.

    Every async/await can be transformed in an equivalent .then(…)-callback program, and works just like that from the concurrency perspective. So while a promise is being awaited, other events may fire and arbitrary other code may run.

提交回复
热议问题