diff --git a/doc/api/timers.md b/doc/api/timers.md index 2b6af6f66f..8abcdcb5cb 100644 --- a/doc/api/timers.md +++ b/doc/api/timers.md @@ -85,6 +85,27 @@ next event loop iteration. If `callback` is not a function, a [`TypeError`][] will be thrown. +*Note*: This method has a custom variant for promises that is available using +[`util.promisify()`][]: + +```js +const util = require('util'); +const setImmediatePromise = util.promisify(setImmediate); + +setImmediatePromise('foobar').then((value) => { + // value === 'foobar' (passing values is optional) + // This is executed after all I/O callbacks. +}); + +// or with async function +async function timerExample() { + console.log('Before I/O callbacks'); + await setImmediatePromise(); + console.log('After I/O callbacks'); +} +timerExample(); +``` + ### setInterval(callback, delay[, ...args])