@@ -170,25 +170,7 @@ next event loop iteration.
170
170
If ` callback ` is not a function, a [ ` TypeError ` ] [ ] will be thrown.
171
171
172
172
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() ` ] [ ] .
192
174
193
175
### ` setInterval(callback[, delay[, ...args]]) `
194
176
<!-- YAML
@@ -208,6 +190,9 @@ set to `1`. Non-integer delays are truncated to an integer.
208
190
209
191
If ` callback ` is not a function, a [ ` TypeError ` ] [ ] will be thrown.
210
192
193
+ This method has a custom variant for promises that is available using
194
+ [ ` timersPromises.setInterval() ` ] [ ] .
195
+
211
196
### ` setTimeout(callback[, delay[, ...args]]) `
212
197
<!-- YAML
213
198
added: v0.0.1
@@ -232,17 +217,7 @@ will be set to `1`. Non-integer delays are truncated to an integer.
232
217
If ` callback ` is not a function, a [ ` TypeError ` ] [ ] will be thrown.
233
218
234
219
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() ` ] [ ] .
246
221
247
222
## Cancelling timers
248
223
@@ -257,8 +232,7 @@ returned Promises will be rejected with an `'AbortError'`.
257
232
For ` setImmediate() ` :
258
233
259
234
``` js
260
- const util = require (' util' );
261
- const setImmediatePromise = util .promisify (setImmediate);
235
+ const { setImmediate: setImmediatePromise } = require (' timers/promises' );
262
236
263
237
const ac = new AbortController ();
264
238
const signal = ac .signal ;
@@ -276,8 +250,7 @@ ac.abort();
276
250
For ` setTimeout() ` :
277
251
278
252
``` js
279
- const util = require (' util' );
280
- const setTimeoutPromise = util .promisify (setTimeout);
253
+ const { setTimeout: setTimeoutPromise } = require (' timers/promises' );
281
254
282
255
const ac = new AbortController ();
283
256
const signal = ac .signal ;
@@ -478,6 +451,8 @@ const interval = 100;
478
451
[ `setImmediate()` ] : #timers_setimmediate_callback_args
479
452
[ `setInterval()` ] : #timers_setinterval_callback_delay_args
480
453
[ `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
482
457
[ `worker_threads` ] : worker_threads.md
483
458
[ primitive ] : #timers_timeout_symbol_toprimitive
0 commit comments