Timeout 类


此对象在 setTimeout()setInterval() 内部创建并返回。 它可以传给 clearTimeout()clearInterval() 以取消已安排的行动。

默认情况下,当使用 setTimeout()setInterval() 安排一个定时器时,只要定时器处于活动状态,则 Node.js 事件循环就会继续运行。 这些函数返回的每个 Timeout 对象都会导出 timeout.ref()timeout.unref() 函数,可用于控制此默认的行为。

This object is created internally and is returned from setTimeout() and setInterval(). It can be passed to either clearTimeout() or clearInterval() in order to cancel the scheduled actions.

By default, when a timer is scheduled using either setTimeout() or setInterval(), the Node.js event loop will continue running as long as the timer is active. Each of the Timeout objects returned by these functions export both timeout.ref() and timeout.unref() functions that can be used to control this default behavior.