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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
  • Loading branch information
marco-ippolito authored and RafaelGSS committed Jan 2, 2024
1 parent efa12a8 commit c31ed51
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 c31ed51

Please sign in to comment.