JavaScript运行机制(二)事件循环
process.nextTick和setImmediate方法
setImmediate(()=>{
console.log(1)
})
process.nextTick(()=>{
console.log(2)
})
console.log(3)
setTimeout(() => {console.log(4)},0)
console.log(5)
// 35241
/*
同步
process
异步
setImmediate(当前时间循环结束然后执行)
*/
事件循环
setImmediate(()=>{
console.log(1)
})
process.nextTick(()=>{
console.log(2)
})
console.log(3)
setTimeout(() => {console.log(4)},0)
setTimeout(() => {console.log(5)},1000)
setTimeout(() => {console.log(6)},0)
console.log(7)
// 3724615