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.