1 | /**
|
2 | * The `timers/promises` API provides an alternative set of timer functions
|
3 | * that return `Promise` objects. The API is accessible via`require('timers/promises')`.
|
4 | *
|
5 | * ```js
|
6 | * import {
|
7 | * setTimeout,
|
8 | * setImmediate,
|
9 | * setInterval,
|
10 | * } from 'timers/promises';
|
11 | * ```
|
12 | * @since v15.0.0
|
13 | */
|
14 | declare module 'timers/promises' {
|
15 | import { TimerOptions } from 'node:timers';
|
16 | /**
|
17 | * ```js
|
18 | * import {
|
19 | * setTimeout,
|
20 | * } from 'timers/promises';
|
21 | *
|
22 | * const res = await setTimeout(100, 'result');
|
23 | *
|
24 | * console.log(res); // Prints 'result'
|
25 | * ```
|
26 | * @since v15.0.0
|
27 | * @param [delay=1] The number of milliseconds to wait before fulfilling the promise.
|
28 | * @param value A value with which the promise is fulfilled.
|
29 | */
|
30 | function setTimeout<T = void>(delay?: number, value?: T, options?: TimerOptions): Promise<T>;
|
31 | /**
|
32 | * ```js
|
33 | * import {
|
34 | * setImmediate,
|
35 | * } from 'timers/promises';
|
36 | *
|
37 | * const res = await setImmediate('result');
|
38 | *
|
39 | * console.log(res); // Prints 'result'
|
40 | * ```
|
41 | * @since v15.0.0
|
42 | * @param value A value with which the promise is fulfilled.
|
43 | */
|
44 | function setImmediate<T = void>(value?: T, options?: TimerOptions): Promise<T>;
|
45 | /**
|
46 | * Returns an async iterator that generates values in an interval of `delay` ms.
|
47 | *
|
48 | * ```js
|
49 | * import {
|
50 | * setInterval,
|
51 | * } from 'timers/promises';
|
52 | *
|
53 | * const interval = 100;
|
54 | * for await (const startTime of setInterval(interval, Date.now())) {
|
55 | * const now = Date.now();
|
56 | * console.log(now);
|
57 | * if ((now - startTime) > 1000)
|
58 | * break;
|
59 | * }
|
60 | * console.log(Date.now());
|
61 | * ```
|
62 | * @since v15.9.0
|
63 | */
|
64 | function setInterval<T = void>(delay?: number, value?: T, options?: TimerOptions): AsyncIterable<T>;
|
65 | }
|
66 | declare module 'node:timers/promises' {
|
67 | export * from 'timers/promises';
|
68 | }
|