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
posted @ 2021-07-27 17:47  `Duet`  阅读(28)  评论(0编辑  收藏  举报