Event Loop浅理解

2019-03-11  本文已影响0人  书简_yu

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

JavaScript 运行机制详解:再谈Event Loop

js执行机制(promise,setTimeout执行顺序)

上一篇下一篇

猜你喜欢

热点阅读