Micro & macro task task

For example with chrome

setTimeout(function(){    console.log('setTimeout')},0)
new Promise(function(resolve){
    console.log('promise')
    resolve()
}).then(function(){
    console.log('then')
})复制代码

Browser eventloop mechanism

js performed as a single-threaded, thus divided into synchronous and asynchronous

Perform a synchronization task, i.e. setTimeout, new Promise, console.log ( 'promise')

Tasks are divided into macro and micro asynchronous tasks,

setTimeout, setInterval as the macro task, Promise for the micro-tasks. Two tasks to be mounted in a different task queue.

Micro-browser to perform a task queue, namely console.log ( 'then') and then executing the macro task console.log ( 'setTimeoout')


Guess you like

Origin blog.csdn.net/weixin_34366546/article/details/91374266