setImmediate(callback[, ...args])
-
callback
<Function> 本轮 Node.js 事件循环 结束时调用的函数¥
callback
<Function> The function to call at the end of this turn of the Node.js Event Loop -
...args
<any> 调用callback
时要传入的可选参数。¥
...args
<any> Optional arguments to pass when thecallback
is called. -
返回:<Immediate> 与
clearImmediate()
配合使用¥Returns: <Immediate> for use with
clearImmediate()
在 I/O 事件回调后安排 callback
的 "immediate" 执行。
¥Schedules the "immediate" execution of the callback
after I/O events'
callbacks.
当多次调用 setImmediate()
时,则 callback
函数会按照它们的创建顺序排队执行。每次事件循环迭代都会处理整个回调队列。如果立即定时器从正在执行的回调中排队,则直到下一次事件循环迭代才会触发该定时器。
¥When multiple calls to setImmediate()
are made, the callback
functions are
queued for execution in the order in which they are created. The entire callback
queue is processed every event loop iteration. If an immediate timer is queued
from inside an executing callback, that timer will not be triggered until the
next event loop iteration.
如果 callback
不是函数,则将抛出 TypeError
。
¥If callback
is not a function, a TypeError
will be thrown.
此方法具有可使用 timersPromises.setImmediate()
获得的 promise 的自定义变体。
¥This method has a custom variant for promises that is available using
timersPromises.setImmediate()
.