Skip to content

Commit e6367c2

Browse files
joyeecheungtargos
authored andcommitted
timers: refactor to use module.exports
PR-URL: #26583 Refs: #26546 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 255de69 commit e6367c2

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

lib/timers.js

+30-30
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,15 @@ function decRefCount() {
185185

186186
// Schedule or re-schedule a timer.
187187
// The item must have been enroll()'d first.
188-
const active = exports.active = function(item) {
188+
function active(item) {
189189
insert(item, true, getLibuvNow());
190-
};
190+
}
191191

192192
// Internal APIs that need timeouts should use `_unrefActive()` instead of
193193
// `active()` so that they do not unnecessarily keep the process open.
194-
exports._unrefActive = function(item) {
194+
function _unrefActive(item) {
195195
insert(item, false, getLibuvNow());
196-
};
197-
196+
}
198197

199198
// The underlying logic for scheduling or re-scheduling a timer.
200199
//
@@ -406,12 +405,6 @@ function unenroll(item) {
406405
item._idleTimeout = -1;
407406
}
408407

409-
exports.unenroll = util.deprecate(unenroll,
410-
'timers.unenroll() is deprecated. ' +
411-
'Please use clearTimeout instead.',
412-
'DEP0096');
413-
414-
415408
// Make a regular object able to act as a timer by setting some properties.
416409
// This function does not start the timer, see `active()`.
417410
// Using existing objects as timers slightly reduces object overhead.
@@ -426,11 +419,6 @@ function enroll(item, msecs) {
426419
item._idleTimeout = msecs;
427420
}
428421

429-
exports.enroll = util.deprecate(enroll,
430-
'timers.enroll() is deprecated. ' +
431-
'Please use setTimeout instead.',
432-
'DEP0095');
433-
434422

435423
/*
436424
* DOM-style timers
@@ -476,18 +464,14 @@ setTimeout[internalUtil.promisify.custom] = function(after, value) {
476464
});
477465
};
478466

479-
exports.setTimeout = setTimeout;
480-
481-
482-
const clearTimeout = exports.clearTimeout = function clearTimeout(timer) {
467+
function clearTimeout(timer) {
483468
if (timer && timer._onTimeout) {
484469
timer._onTimeout = null;
485470
unenroll(timer);
486471
}
487-
};
488-
472+
}
489473

490-
exports.setInterval = function setInterval(callback, repeat, arg1, arg2, arg3) {
474+
function setInterval(callback, repeat, arg1, arg2, arg3) {
491475
if (typeof callback !== 'function') {
492476
throw new ERR_INVALID_CALLBACK();
493477
}
@@ -517,14 +501,14 @@ exports.setInterval = function setInterval(callback, repeat, arg1, arg2, arg3) {
517501
active(timeout);
518502

519503
return timeout;
520-
};
504+
}
521505

522-
exports.clearInterval = function clearInterval(timer) {
506+
function clearInterval(timer) {
523507
// clearTimeout and clearInterval can be used to clear timers created from
524508
// both setTimeout and setInterval, as specified by HTML Living Standard:
525509
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-setinterval
526510
clearTimeout(timer);
527-
};
511+
}
528512

529513

530514
Timeout.prototype.unref = function() {
@@ -739,10 +723,7 @@ setImmediate[internalUtil.promisify.custom] = function(value) {
739723
return new Promise((resolve) => new Immediate(resolve, [value]));
740724
};
741725

742-
exports.setImmediate = setImmediate;
743-
744-
745-
exports.clearImmediate = function clearImmediate(immediate) {
726+
function clearImmediate(immediate) {
746727
if (!immediate || immediate._destroyed)
747728
return;
748729

@@ -760,4 +741,23 @@ exports.clearImmediate = function clearImmediate(immediate) {
760741
immediate._onImmediate = null;
761742

762743
immediateQueue.remove(immediate);
744+
}
745+
746+
module.exports = {
747+
_unrefActive,
748+
active,
749+
setTimeout,
750+
clearTimeout,
751+
setImmediate,
752+
clearImmediate,
753+
setInterval,
754+
clearInterval,
755+
unenroll: util.deprecate(
756+
unenroll,
757+
'timers.unenroll() is deprecated. Please use clearTimeout instead.',
758+
'DEP0096'),
759+
enroll: util.deprecate(
760+
enroll,
761+
'timers.enroll() is deprecated. Please use setTimeout instead.',
762+
'DEP0095')
763763
};

0 commit comments

Comments
 (0)