timersPromises.scheduler.wait(delay[, options])


稳定性: 1 - 实验性的

¥Stability: 1 - Experimental

  • delay <number> 解决 promise 前等待的毫秒数。

    ¥delay <number> The number of milliseconds to wait before resolving the promise.

  • options <Object>

    • ref <boolean> 设置为 false 以指示调度的 Timeout 不应要求 Node.js 事件循环保持活动状态。默认值:true

      ¥ref <boolean> Set to false to indicate that the scheduled Timeout should not require the Node.js event loop to remain active. Default: true.

    • signal <AbortSignal> 可用于取消等待的可选 AbortSignal

      ¥signal <AbortSignal> An optional AbortSignal that can be used to cancel waiting.

  • 返回:<Promise>

    ¥Returns: <Promise>

调度 API 规范草案定义的实验性 API 正在开发为标准 Web 平台 API。

¥An experimental API defined by the Scheduling APIs draft specification being developed as a standard Web Platform API.

调用 timersPromises.scheduler.wait(delay, options) 相当于调用 timersPromises.setTimeout(delay, undefined, options)

¥Calling timersPromises.scheduler.wait(delay, options) is equivalent to calling timersPromises.setTimeout(delay, undefined, options).

import { scheduler } from 'node:timers/promises';

await scheduler.wait(1000); // Wait one second before continuing