timers: introduce timers/promises
Move the promisified timers implementations into a new experimental sub-module to avoid the need to promisify. The promisified versions now return the timers/promises versions.
Also adds ref
option to the promisified versions
const {
setTimeout,
setImmediate
} = require('timers/promises');
setTimeout(10, null, { ref: false })
.then(console.log);
setImmediate(null, { ref: false })
.then(console.log);
// The promisify versions of the original timers return the same functions...
const timers = require('timers');
const { promisify } = require('util');
const assert = require('assert');
assert.strictEqual(promisify(timers.setTimeout), setTimeout);
assert.strictEqual(promisify(timers.setImmediate), setImmediate);
Needs the additional fixes implemented in https://github.com/nodejs/node/pull/33949 ... this one is blocked on that one landing.
Signed-off-by: James M Snell jasnell@gmail.com
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines