Skip to content

Commit

Permalink
timers: export timers.promises
Browse files Browse the repository at this point in the history
PR-URL: #51246
Fixes: #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>
  • Loading branch information
marco-ippolito authored Dec 23, 2023
1 parent 857a34b commit 6329d2c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
const {
MathTrunc,
ObjectDefineProperty,
ObjectDefineProperties,
SymbolDispose,
SymbolToPrimitive,
} = primordials;
Expand Down Expand Up @@ -62,6 +63,7 @@ let debug = require('internal/util/debuglog').debuglog('timer', (fn) => {
const { validateFunction } = require('internal/validators');

let timersPromises;
let timers;

const {
destroyHooksExist,
Expand Down Expand Up @@ -347,7 +349,7 @@ Immediate.prototype[SymbolDispose] = function() {
clearImmediate(this);
};

module.exports = {
module.exports = timers = {
setTimeout,
clearTimeout,
setImmediate,
Expand All @@ -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 changes: 12 additions & 0 deletions test/parallel/test-timers-promises.js
Original file line number Diff line number Diff line change
@@ -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);
}));

0 comments on commit 6329d2c

Please sign in to comment.