NodeJS - setTimeout(fn,0) vs setImmediate(fn)

前端 未结 9 1315
暖寄归人
暖寄归人 2020-12-07 13:23

What is the difference between those two, and when will I use one over the other?

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 13:47

    use setImmediate() for not blocking the event loop. The callback will run on the next event loop, as soon as the current one is done.

    use setTimeout() for controlled delays. The function will run after the specified delay. The minimum delay is 1 millisecond.

提交回复
热议问题