1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
/**
* The `timers/promises` API provides an alternative set of timer functions
* that return `Promise` objects. The API is accessible via
* `require('node:timers/promises')`.
*
* ```js
* import {
* setTimeout,
* setImmediate,
* setInterval,
* } from 'node:timers/promises';
* ```
* @since v15.0.0
* @see [source](https://github.com/nodejs/node/blob/v20.x/lib/timers/promises.js)
*/
declare module "timers/promises" {
import { TimerOptions } from "node:timers";
/**
* ```js
* import {
* setTimeout,
* } from 'node:timers/promises';
*
* const res = await setTimeout(100, 'result');
*
* console.log(res); // Prints 'result'
* ```
* @since v15.0.0
* @param delay The number of milliseconds to wait before fulfilling the
* promise. **Default:** `1`.
* @param value A value with which the promise is fulfilled.
*/
function setTimeout<T = void>(delay?: number, value?: T, options?: TimerOptions): Promise<T>;
/**
* ```js
* import {
* setImmediate,
* } from 'node:timers/promises';
*
* const res = await setImmediate('result');
*
* console.log(res); // Prints 'result'
* ```
* @since v15.0.0
* @param value A value with which the promise is fulfilled.
*/
function setImmediate<T = void>(value?: T, options?: TimerOptions): Promise<T>;
/**
* Returns an async iterator that generates values in an interval of `delay` ms.
* If `ref` is `true`, you need to call `next()` of async iterator explicitly
* or implicitly to keep the event loop alive.
*
* ```js
* import {
* setInterval,
* } from 'node:timers/promises';
*
* const interval = 100;
* for await (const startTime of setInterval(interval, Date.now())) {
* const now = Date.now();
* console.log(now);
* if ((now - startTime) > 1000)
* break;
* }
* console.log(Date.now());
* ```
* @since v15.9.0
* @param delay The number of milliseconds to wait between iterations.
* **Default:** `1`.
* @param value A value with which the iterator returns.
*/
function setInterval<T = void>(delay?: number, value?: T, options?: TimerOptions): NodeJS.AsyncIterator<T>;
interface Scheduler {
/**
* An experimental API defined by the [Scheduling APIs](https://github.com/WICG/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.
*
* ```js
* import { scheduler } from 'node:timers/promises';
*
* await scheduler.wait(1000); // Wait one second before continuing
* ```
* @since v17.3.0, v16.14.0
* @experimental
* @param delay The number of milliseconds to wait before resolving the
* promise.
*/
wait(delay: number, options?: { signal?: AbortSignal }): Promise<void>;
/**
* An experimental API defined by the [Scheduling APIs](https://github.com/WICG/scheduling-apis) draft specification
* being developed as a standard Web Platform API.
*
* Calling `timersPromises.scheduler.yield()` is equivalent to calling
* `timersPromises.setImmediate()` with no arguments.
* @since v17.3.0, v16.14.0
* @experimental
*/
yield(): Promise<void>;
}
const scheduler: Scheduler;
}
declare module "node:timers/promises" {
export * from "timers/promises";
}
|