Promise

本文共 116 字 预计花费 1 分钟

学学 Promise

Timing

function passed to .then will never be called synchronously,even with an already-resolved promise.

1
2
Promise.resolve().then(() => console.log(2));
console.log(1) // 1, 2

instead of running immediately, the passed-in function is put on a microtask queue, which means it runs later when the queue is emptied at the end of the current run of the Javascript event loop.

相对于立即调用,被传入的回调函数会被放置到一个 microtask 队列中,这意味着只有当当前的事件循环结束后才会被调用。

Copyright © 2017 - 2018 空脑壳 All Rights Reserved.

冀ICP备17022284号