Polymers this.async、Promise.then 和 setTimeout 函数有什么区别?
我的理解:
this.async 和 Promise.then 将一个 Task 移动到当前 Stack 的末尾并且 setTimeout 被处理为新的 Task 并在 eventloop 从队列中取出一个新任务时在下一个循环中执行?
如有错误请指正
最佳答案
TLDR:是的,但请注意 this.async
uses setTimeout
如果指定了超时。
Polymer.Async.run
(this.async
) 没有超时 - 排队一个微任务(通过MutationObserver
回调)Polymer.Async.run
(this.async
) 超时 - 排队宏任务<Promise.then
- 将微任务排入队列setTimeout
- 将宏任务排入队列
Difference between microtask and macrotask within an event loop context
关于asynchronous - polymer this.async vs Promise.then vs setTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47694896/