Polymers this.async,Promise.then和setTimeout函数之间有什么区别?
我的理解:
this.async和Promise.then然后将Task移到当前Stack的末尾,并且当eventloop从队列中获取新任务时,setTimeout将作为新Task处理并在下一个循环中执行?
如果我错了,请纠正我。
最佳答案
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