javascript.basics icon indicating copy to clipboard operation
javascript.basics copied to clipboard

宏任务、微任务与Event Loop

Open Kelichao opened this issue 5 years ago • 0 comments

  1. Event Loop(事件轮询)
  2. macro-task(宏任务) 包括整体代码script、setTimeout,setInterval,I/O
  3. micro-task(微任务):Promise、process.nextTick
  • 输出为1,2, 3
// 下一次的宏任务
setTimeout(() => {
  console.log(3)
},0)

new Promise(function(resolve) {
  // 正常顺序执行
    console.log('1');
    resolve();
}).then(function() {
  // 微任务
    console.log('2')
})

Kelichao avatar Jul 27 '20 07:07 Kelichao