mirror of https://github.com/lukechilds/node.git
Browse Source
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>v6
Anna Henningsen
8 years ago
3 changed files with 102 additions and 2 deletions
@ -0,0 +1,40 @@ |
|||
'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'); |
|||
})); |
|||
} |
Loading…
Reference in new issue