event loop
task queue中取任务
同步任务立即执行
异步任务挂起来,可以执行时放入task queue
执行完再去取任务
// 同步任务中此为microtask, 会在本轮事件循环的末尾执行
Promise.resolve().then(() => {
console.log('bbb');
})
Tasks execute in order, and the browser may render between them
Microtasks execute in order, and are executed:
after every callback, as long as no other JavaScript is mid-execution
at the end of each task
摘录自第一篇参考文章
- 参考
Tasks, microtasks, queues and schedules
网友评论