timers: refactor to use module.exports · nodejs/node@e6367c2 (original) (raw)
`@@ -185,16 +185,15 @@ function decRefCount() {
`
185
185
``
186
186
`// Schedule or re-schedule a timer.
`
187
187
`// The item must have been enroll()'d first.
`
188
``
`-
const active = exports.active = function(item) {
`
``
188
`+
function active(item) {
`
189
189
`insert(item, true, getLibuvNow());
`
190
``
`-
};
`
``
190
`+
}
`
191
191
``
192
192
`` // Internal APIs that need timeouts should use _unrefActive()
instead of
``
193
193
`` // active()
so that they do not unnecessarily keep the process open.
``
194
``
`-
exports._unrefActive = function(item) {
`
``
194
`+
function _unrefActive(item) {
`
195
195
`insert(item, false, getLibuvNow());
`
196
``
`-
};
`
197
``
-
``
196
`+
}
`
198
197
``
199
198
`// The underlying logic for scheduling or re-scheduling a timer.
`
200
199
`//
`
`@@ -406,12 +405,6 @@ function unenroll(item) {
`
406
405
`item._idleTimeout = -1;
`
407
406
`}
`
408
407
``
409
``
`-
exports.unenroll = util.deprecate(unenroll,
`
410
``
`-
'timers.unenroll() is deprecated. ' +
`
411
``
`-
'Please use clearTimeout instead.',
`
412
``
`-
'DEP0096');
`
413
``
-
414
``
-
415
408
`// Make a regular object able to act as a timer by setting some properties.
`
416
409
`` // This function does not start the timer, see active()
.
``
417
410
`// Using existing objects as timers slightly reduces object overhead.
`
`@@ -426,11 +419,6 @@ function enroll(item, msecs) {
`
426
419
`item._idleTimeout = msecs;
`
427
420
`}
`
428
421
``
429
``
`-
exports.enroll = util.deprecate(enroll,
`
430
``
`-
'timers.enroll() is deprecated. ' +
`
431
``
`-
'Please use setTimeout instead.',
`
432
``
`-
'DEP0095');
`
433
``
-
434
422
``
435
423
`/*
`
436
424
` * DOM-style timers
`
`@@ -476,18 +464,14 @@ setTimeout[internalUtil.promisify.custom] = function(after, value) {
`
476
464
`});
`
477
465
`};
`
478
466
``
479
``
`-
exports.setTimeout = setTimeout;
`
480
``
-
481
``
-
482
``
`-
const clearTimeout = exports.clearTimeout = function clearTimeout(timer) {
`
``
467
`+
function clearTimeout(timer) {
`
483
468
`if (timer && timer._onTimeout) {
`
484
469
`timer._onTimeout = null;
`
485
470
`unenroll(timer);
`
486
471
`}
`
487
``
`-
};
`
488
``
-
``
472
`+
}
`
489
473
``
490
``
`-
exports.setInterval = function setInterval(callback, repeat, arg1, arg2, arg3) {
`
``
474
`+
function setInterval(callback, repeat, arg1, arg2, arg3) {
`
491
475
`if (typeof callback !== 'function') {
`
492
476
`throw new ERR_INVALID_CALLBACK();
`
493
477
`}
`
`@@ -517,14 +501,14 @@ exports.setInterval = function setInterval(callback, repeat, arg1, arg2, arg3) {
`
517
501
`active(timeout);
`
518
502
``
519
503
`return timeout;
`
520
``
`-
};
`
``
504
`+
}
`
521
505
``
522
``
`-
exports.clearInterval = function clearInterval(timer) {
`
``
506
`+
function clearInterval(timer) {
`
523
507
`// clearTimeout and clearInterval can be used to clear timers created from
`
524
508
`// both setTimeout and setInterval, as specified by HTML Living Standard:
`
525
509
`// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-setinterval
`
526
510
`clearTimeout(timer);
`
527
``
`-
};
`
``
511
`+
}
`
528
512
``
529
513
``
530
514
`Timeout.prototype.unref = function() {
`
`@@ -739,10 +723,7 @@ setImmediate[internalUtil.promisify.custom] = function(value) {
`
739
723
`return new Promise((resolve) => new Immediate(resolve, [value]));
`
740
724
`};
`
741
725
``
742
``
`-
exports.setImmediate = setImmediate;
`
743
``
-
744
``
-
745
``
`-
exports.clearImmediate = function clearImmediate(immediate) {
`
``
726
`+
function clearImmediate(immediate) {
`
746
727
`if (!immediate || immediate._destroyed)
`
747
728
`return;
`
748
729
``
`@@ -760,4 +741,23 @@ exports.clearImmediate = function clearImmediate(immediate) {
`
760
741
`immediate._onImmediate = null;
`
761
742
``
762
743
`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')
`
763
763
`};
`