Skip to content

Commit

Permalink
timers: export timers.promises
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Dec 21, 2023
1 parent abbdc3e commit 6209ba4
Show file tree
Hide file tree
Showing 2 changed files with 29 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;
},
},
});
14 changes: 14 additions & 0 deletions test/parallel/test-timers-promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'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(() => {
for (const property of Object.keys(timerPromises)) {
assert.deepStrictEqual(timer.promises[property], timerPromises[property]);
}
}));

0 comments on commit 6209ba4

Please sign in to comment.