@@ -170,25 +170,7 @@ next event loop iteration.
170170If ` callback ` is not a function, a [ ` TypeError ` ] [ ] will be thrown.
171171
172172This 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
209191If ` 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
213198added: v0.0.1
@@ -232,17 +217,7 @@ will be set to `1`. Non-integer delays are truncated to an integer.
232217If ` callback ` is not a function, a [ ` TypeError ` ] [ ] will be thrown.
233218
234219This 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'`.
257232For ` setImmediate() ` :
258233
259234``` js
260- const util = require (' util' );
261- const setImmediatePromise = util .promisify (setImmediate);
235+ const { setImmediate: setImmediatePromise } = require (' timers/promises' );
262236
263237const ac = new AbortController ();
264238const signal = ac .signal ;
@@ -276,8 +250,7 @@ ac.abort();
276250For ` setTimeout() ` :
277251
278252``` js
279- const util = require (' util' );
280- const setTimeoutPromise = util .promisify (setTimeout);
253+ const { setTimeout: setTimeoutPromise } = require (' timers/promises' );
281254
282255const ac = new AbortController ();
283256const 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