goodBlog icon indicating copy to clipboard operation
goodBlog copied to clipboard

node事件循环 > 3.微任务(microtack)

Open langyuxiansheng opened this issue 5 years ago • 0 comments

http://www.inode.club/#/node/eventLoop 输出结果 展示错了吧

/输出结果3,4

process.nextTick(() => console.log(1)); Promise.resolve().then(() => console.log(2)); process.nextTick(() => console.log(3)); Promise.resolve().then(() => console.log(4)); //输出结果 1,3,3,4

注意,只有前一个队列全部清空以后,才会执行下一个队列。两个队列的概念 nextTickQueue 和微队列microTaskQueue,也就是说开启异步任务也分为几种,像promise对象这种,开启之后直接进入微队列中,微队列内的就是那个任务快就那个先执行完,但是针对于队列与队列之间不同的任务,还是会有先后顺序,这个先后顺序是由队列决定的。

langyuxiansheng avatar Nov 19 '19 06:11 langyuxiansheng