mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 20:31:36 +00:00

Add support for `util.promisify(setTimeout)` and `util.promisify(setImmediate)` as a proof-of-concept implementation. `clearTimeout()` and `clearImmediate()` do not work on those Promises. Includes documentation and tests. PR-URL: https://github.com/nodejs/node/pull/12442 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: William Kapke <william.kapke@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
41 lines
883 B
JavaScript
41 lines
883 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const timers = require('timers');
|
|
const { promisify } = require('util');
|
|
|
|
/* eslint-disable no-restricted-syntax */
|
|
|
|
common.crashOnUnhandledRejection();
|
|
|
|
const setTimeout = promisify(timers.setTimeout);
|
|
const setImmediate = promisify(timers.setImmediate);
|
|
|
|
{
|
|
const promise = setTimeout(1);
|
|
promise.then(common.mustCall((value) => {
|
|
assert.strictEqual(value, undefined);
|
|
}));
|
|
}
|
|
|
|
{
|
|
const promise = setTimeout(1, 'foobar');
|
|
promise.then(common.mustCall((value) => {
|
|
assert.strictEqual(value, 'foobar');
|
|
}));
|
|
}
|
|
|
|
{
|
|
const promise = setImmediate();
|
|
promise.then(common.mustCall((value) => {
|
|
assert.strictEqual(value, undefined);
|
|
}));
|
|
}
|
|
|
|
{
|
|
const promise = setImmediate('foobar');
|
|
promise.then(common.mustCall((value) => {
|
|
assert.strictEqual(value, 'foobar');
|
|
}));
|
|
}
|