timersPromises.setImmediate([value[, options]])


  • value <any> 履行 promise 使用的值。
  • options <Object>
    • ref <boolean> 设置为 false 以指示调度的 Immediate 不应要求 Node.js 事件循环保持活动状态。 默认值: true
    • signal <AbortSignal> 可选的 AbortSignal,可用于取消调度的 Immediate
import {
  setImmediate,
} from 'timers/promises';

const res = await setImmediate('result');

console.log(res);  // 打印 'result'const {
  setImmediate,
} = require('node:timers/promises');

setImmediate('result').then((res) => {
  console.log(res);  // 打印 'result'
});
  • value <any> A value with which the promise is fulfilled.
  • options <Object>
    • ref <boolean> Set to false to indicate that the scheduled Immediate should not require the Node.js event loop to remain active. Default: true.
    • signal <AbortSignal> An optional AbortSignal that can be used to cancel the scheduled Immediate.
import {
  setImmediate,
} from 'timers/promises';

const res = await setImmediate('result');

console.log(res);  // Prints 'result'const {
  setImmediate,
} = require('node:timers/promises');

setImmediate('result').then((res) => {
  console.log(res);  // Prints 'result'
});