Skip to content

Commit e266350

Browse files
foxxyztargos
authored andcommitted
doc: replace outdated util.promisify timer examples with references
PR-URL: #39164 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f6a1092 commit e266350

File tree

1 file changed

+10
-35
lines changed

1 file changed

+10
-35
lines changed

Diff for: doc/api/timers.md

+10-35
Original file line numberDiff line numberDiff line change
@@ -170,25 +170,7 @@ next event loop iteration.
170170
If `callback` is not a function, a [`TypeError`][] will be thrown.
171171

172172
This method has a custom variant for promises that is available using
173-
[`util.promisify()`][]:
174-
175-
```js
176-
const util = require('util');
177-
const setImmediatePromise = util.promisify(setImmediate);
178-
179-
setImmediatePromise('foobar').then((value) => {
180-
// value === 'foobar' (passing values is optional)
181-
// This is executed after all I/O callbacks.
182-
});
183-
184-
// Or with async function
185-
async function timerExample() {
186-
console.log('Before I/O callbacks');
187-
await setImmediatePromise();
188-
console.log('After I/O callbacks');
189-
}
190-
timerExample();
191-
```
173+
[`timersPromises.setImmediate()`][].
192174

193175
### `setInterval(callback[, delay[, ...args]])`
194176
<!-- YAML
@@ -208,6 +190,9 @@ set to `1`. Non-integer delays are truncated to an integer.
208190

209191
If `callback` is not a function, a [`TypeError`][] will be thrown.
210192

193+
This method has a custom variant for promises that is available using
194+
[`timersPromises.setInterval()`][].
195+
211196
### `setTimeout(callback[, delay[, ...args]])`
212197
<!-- YAML
213198
added: v0.0.1
@@ -232,17 +217,7 @@ will be set to `1`. Non-integer delays are truncated to an integer.
232217
If `callback` is not a function, a [`TypeError`][] will be thrown.
233218

234219
This method has a custom variant for promises that is available using
235-
[`util.promisify()`][]:
236-
237-
```js
238-
const util = require('util');
239-
const setTimeoutPromise = util.promisify(setTimeout);
240-
241-
setTimeoutPromise(40, 'foobar').then((value) => {
242-
// value === 'foobar' (passing values is optional)
243-
// This is executed after about 40 milliseconds.
244-
});
245-
```
220+
[`timersPromises.setTimeout()`][].
246221

247222
## Cancelling timers
248223

@@ -257,8 +232,7 @@ returned Promises will be rejected with an `'AbortError'`.
257232
For `setImmediate()`:
258233

259234
```js
260-
const util = require('util');
261-
const setImmediatePromise = util.promisify(setImmediate);
235+
const { setImmediate: setImmediatePromise } = require('timers/promises');
262236

263237
const ac = new AbortController();
264238
const signal = ac.signal;
@@ -276,8 +250,7 @@ ac.abort();
276250
For `setTimeout()`:
277251

278252
```js
279-
const util = require('util');
280-
const setTimeoutPromise = util.promisify(setTimeout);
253+
const { setTimeout: setTimeoutPromise } = require('timers/promises');
281254

282255
const ac = new AbortController();
283256
const signal = ac.signal;
@@ -478,6 +451,8 @@ const interval = 100;
478451
[`setImmediate()`]: #timers_setimmediate_callback_args
479452
[`setInterval()`]: #timers_setinterval_callback_delay_args
480453
[`setTimeout()`]: #timers_settimeout_callback_delay_args
481-
[`util.promisify()`]: util.md#util_util_promisify_original
454+
[`timersPromises.setImmediate()`]: #timers_timerspromises_setimmediate_value_options
455+
[`timersPromises.setInterval()`]: #timers_timerspromises_setinterval_delay_value_options
456+
[`timersPromises.setTimeout()`]: #timers_timerspromises_settimeout_delay_value_options
482457
[`worker_threads`]: worker_threads.md
483458
[primitive]: #timers_timeout_symbol_toprimitive

0 commit comments

Comments
 (0)