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

稳定性: 1 - 实验

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

调用 timersPromises.scheduler.wait(delay, options) 大致相当于调用 timersPromises.setTimeout(delay, undefined, options),只是不支持 ref 选项。

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

await scheduler.wait(1000); // 等待一秒钟后再继续

Stability: 1 - Experimental

  • delay <number> The number of milliseconds to wait before resolving the promise.
  • options <Object>
    • signal <AbortSignal> An optional AbortSignal that can be used to cancel waiting.
  • Returns: <Promise>

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

Calling timersPromises.scheduler.wait(delay, options) is roughly equivalent to calling timersPromises.setTimeout(delay, undefined, options) except that the ref option is not supported.

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

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