How does setTimeout work in Node.JS?

后端 未结 5 1016
心在旅途
心在旅途 2020-11-30 19:35

I guess that once it\'s executed it\'s on the queue, but in the queue is there any assurance it will invoke exactly after X milliseconds? Or will other heavy tasks higher on

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 20:28

    setTimeout(callback,t) is used to run callback after at least t millisecond. The actual delay depends on many external factors like OS timer granularity and system load.

    So, there is a possibility that it will be called slightly after the set time, but will never be called before.

    A timer can't span more than 24.8 days.

提交回复
热议问题