mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
timers: export timers.promises
PR-URL: https://github.com/nodejs/node/pull/51246 Fixes: https://github.com/nodejs/node/issues/51237 Reviewed-By: Raz Luvaton <rluvaton@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
parent
857a34bddb
commit
6329d2cd27
@ -24,6 +24,7 @@
|
||||
const {
|
||||
MathTrunc,
|
||||
ObjectDefineProperty,
|
||||
ObjectDefineProperties,
|
||||
SymbolDispose,
|
||||
SymbolToPrimitive,
|
||||
} = primordials;
|
||||
@ -62,6 +63,7 @@ let debug = require('internal/util/debuglog').debuglog('timer', (fn) => {
|
||||
const { validateFunction } = require('internal/validators');
|
||||
|
||||
let timersPromises;
|
||||
let timers;
|
||||
|
||||
const {
|
||||
destroyHooksExist,
|
||||
@ -347,7 +349,7 @@ Immediate.prototype[SymbolDispose] = function() {
|
||||
clearImmediate(this);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
module.exports = timers = {
|
||||
setTimeout,
|
||||
clearTimeout,
|
||||
setImmediate,
|
||||
@ -372,3 +374,15 @@ module.exports = {
|
||||
'timers.enroll() is deprecated. Please use setTimeout instead.',
|
||||
'DEP0095'),
|
||||
};
|
||||
|
||||
ObjectDefineProperties(timers, {
|
||||
promises: {
|
||||
__proto__: null,
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
timersPromises ??= require('timers/promises');
|
||||
return timersPromises;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
12
test/parallel/test-timers-promises.js
Normal file
12
test/parallel/test-timers-promises.js
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
const timer = require('node:timers');
|
||||
const timerPromises = require('node:timers/promises');
|
||||
const assert = require('assert');
|
||||
const { test } = require('node:test');
|
||||
|
||||
test('(node:timers/promises) is equal to (node:timers).promises', common.mustCall(() => {
|
||||
assert.deepStrictEqual(timerPromises, timer.promises);
|
||||
}));
|
||||
Loading…
Reference in New Issue
Block a user