timers: set several methods EOL

PR-URL: https://github.com/nodejs/node/pull/56966
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
Yagiz Nizipli
2025-02-10 16:09:41 -05:00
committed by GitHub
parent 3ea97d5c25
commit 5d7091f1bc
10 changed files with 22 additions and 262 deletions

View File

@@ -2065,28 +2065,34 @@ method.
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/56966
description: End-of-Life.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18066
description: Runtime deprecation.
-->
Type: Runtime
Type: End-of-Life
`timers.enroll()` is deprecated. Please use the publicly documented
`timers.enroll()` has been removed. Please use the publicly documented
[`setTimeout()`][] or [`setInterval()`][] instead.
### DEP0096: `timers.unenroll()`
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/56966
description: End-of-Life.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18066
description: Runtime deprecation.
-->
Type: Runtime
Type: End-of-Life
`timers.unenroll()` is deprecated. Please use the publicly documented
`timers.unenroll()` has been removed. Please use the publicly documented
[`clearTimeout()`][] or [`clearInterval()`][] instead.
### DEP0097: `MakeCallback` with `domain` property
@@ -2613,14 +2619,17 @@ The `node:_stream_wrap` module is deprecated.
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/56966
description: End-of-Life.
- version: v11.14.0
pr-url: https://github.com/nodejs/node/pull/26760
description: Runtime deprecation.
-->
Type: Runtime
Type: End-of-Life
The previously undocumented `timers.active()` is deprecated.
The previously undocumented `timers.active()` has been removed.
Please use the publicly documented [`timeout.refresh()`][] instead.
If re-referencing the timeout is necessary, [`timeout.ref()`][] can be used
with no performance impact since Node.js 10.
@@ -2629,14 +2638,17 @@ with no performance impact since Node.js 10.
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/56966
description: End-of-Life.
- version: v11.14.0
pr-url: https://github.com/nodejs/node/pull/26760
description: Runtime deprecation.
-->
Type: Runtime
Type: End-of-Life
The previously undocumented and "private" `timers._unrefActive()` is deprecated.
The previously undocumented and "private" `timers._unrefActive()` has been removed.
Please use the publicly documented [`timeout.refresh()`][] instead.
If unreferencing the timeout is necessary, [`timeout.unref()`][] can be used
with no performance impact since Node.js 10.

View File

@@ -46,18 +46,14 @@ const {
},
kRefed,
kHasPrimitive,
getTimerDuration,
timerListMap,
timerListQueue,
immediateQueue,
active,
unrefActive,
insert,
knownTimersById,
} = require('internal/timers');
const {
promisify: { custom: customPromisify },
deprecate,
} = require('internal/util');
let debug = require('internal/util/debuglog').debuglog('timer', (fn) => {
debug = fn;
@@ -111,20 +107,6 @@ function unenroll(item) {
item._idleTimeout = -1;
}
// Make a regular object able to act as a timer by setting some properties.
// This function does not start the timer, see `active()`.
// Using existing objects as timers slightly reduces object overhead.
function enroll(item, msecs) {
msecs = getTimerDuration(msecs, 'msecs');
// If this item was already in a list somewhere
// then we should unenroll it from that
if (item._idleNext) unenroll(item);
L.init(item);
item._idleTimeout = msecs;
}
/**
* Schedules the execution of a one-time `callback`
@@ -351,23 +333,6 @@ module.exports = timers = {
clearImmediate,
setInterval,
clearInterval,
_unrefActive: deprecate(
unrefActive,
'timers._unrefActive() is deprecated.' +
' Please use timeout.refresh() instead.',
'DEP0127'),
active: deprecate(
active,
'timers.active() is deprecated. Please use timeout.refresh() instead.',
'DEP0126'),
unenroll: deprecate(
unenroll,
'timers.unenroll() is deprecated. Please use clearTimeout instead.',
'DEP0096'),
enroll: deprecate(
enroll,
'timers.enroll() is deprecated. Please use setTimeout instead.',
'DEP0095'),
};
ObjectDefineProperties(timers, {

View File

@@ -1,34 +0,0 @@
'use strict';
require('../common');
const assert = require('assert');
const active = require('timers').active;
// active() should create timers for these
const legitTimers = [
{ _idleTimeout: 0 },
{ _idleTimeout: 1 },
];
legitTimers.forEach(function(legit) {
const savedTimeout = legit._idleTimeout;
active(legit);
// active() should mutate these objects
assert.strictEqual(legit._idleTimeout, savedTimeout);
assert(Number.isInteger(legit._idleStart));
assert(legit._idleNext);
assert(legit._idlePrev);
});
// active() should not create a timer for these
const bogusTimers = [
{ _idleTimeout: -1 },
{ _idleTimeout: undefined },
];
bogusTimers.forEach(function(bogus) {
const savedTimeout = bogus._idleTimeout;
active(bogus);
// active() should not mutate these objects
assert.deepStrictEqual(bogus, { _idleTimeout: savedTimeout });
});

View File

@@ -1,38 +0,0 @@
'use strict';
require('../common');
const assert = require('assert');
const timers = require('timers');
[
{},
[],
'foo',
() => { },
Symbol('foo'),
].forEach((val) => {
assert.throws(
() => timers.enroll({}, val),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
}
);
});
[
-1,
Infinity,
NaN,
].forEach((val) => {
assert.throws(
() => timers.enroll({}, val),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "msecs" is out of range. ' +
'It must be a non-negative finite number. ' +
`Received ${val}`
}
);
});

View File

@@ -1,16 +0,0 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const timers = require('timers');
const enrollObj = {
_onTimeout: common.mustCall(),
};
timers.enroll(enrollObj, 1);
assert.strictEqual(enrollObj._idleTimeout, 1);
timers.enroll(enrollObj, 10);
assert.strictEqual(enrollObj._idleTimeout, 10);
timers.active(enrollObj);

View File

@@ -2,7 +2,6 @@
const common = require('../common');
const assert = require('assert');
const timers = require('timers');
const OVERFLOW = Math.pow(2, 31); // TIMEOUT_MAX is 2^31-1
@@ -19,7 +18,7 @@ process.on('warning', common.mustCall((warning) => {
assert.strictEqual(lines[0], `${OVERFLOW} does not fit into a 32-bit signed` +
' integer.');
assert.strictEqual(lines.length, 2);
}, 6));
}, 2));
{
@@ -31,12 +30,3 @@ process.on('warning', common.mustCall((warning) => {
const interval = setInterval(timerNotCanceled, OVERFLOW);
clearInterval(interval);
}
{
const timer = {
_onTimeout: timerNotCanceled
};
timers.enroll(timer, OVERFLOW);
timers.active(timer);
timers.unenroll(timer);
}

View File

@@ -1,7 +1,6 @@
'use strict';
const common = require('../common');
const timers = require('timers');
{
const interval = setInterval(common.mustCall(() => {
@@ -17,7 +16,7 @@ const timers = require('timers');
{
const interval = setInterval(common.mustCall(() => {
timers.unenroll(interval);
clearInterval(interval);
}), 1).unref();
}

View File

@@ -1,47 +0,0 @@
'use strict';
// This test is aimed at making sure that unref timers queued with
// timers._unrefActive work correctly.
//
// Basically, it queues one timer in the unref queue, and then queues
// it again each time its timeout callback is fired until the callback
// has been called ten times.
//
// At that point, it unenrolls the unref timer so that its timeout callback
// is not fired ever again.
//
// Finally, a ref timeout is used with a delay large enough to make sure that
// all 10 timeouts had the time to expire.
require('../common');
const timers = require('timers');
const assert = require('assert');
const someObject = {};
let nbTimeouts = 0;
// libuv 0.10.x uses GetTickCount on Windows to implement timers, which uses
// system's timers whose resolution is between 10 and 16ms. See
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms724408.aspx
// for more information. That's the lowest resolution for timers across all
// supported platforms. We're using it as the lowest common denominator,
// and thus expect 5 timers to be able to fire in under 100 ms.
const N = 5;
const TEST_DURATION = 1000;
timers.unenroll(someObject);
timers.enroll(someObject, 1);
someObject._onTimeout = function _onTimeout() {
++nbTimeouts;
if (nbTimeouts === N) timers.unenroll(someObject);
timers._unrefActive(someObject);
};
timers._unrefActive(someObject);
setTimeout(function() {
assert.strictEqual(nbTimeouts, N);
}, TEST_DURATION);

View File

@@ -1,41 +0,0 @@
'use strict';
// The goal of this test is to make sure that, after the regression introduced
// by 934bfe23a16556d05bfb1844ef4d53e8c9887c3d, the fix preserves the following
// behavior of unref timers: if two timers are scheduled to fire at the same
// time, if one unenrolls the other one in its _onTimeout callback, the other
// one will *not* fire.
// This behavior is a private implementation detail and should not be
// considered public interface.
require('../common');
const timers = require('timers');
const assert = require('assert');
let nbTimersFired = 0;
const foo = {
_onTimeout: function() {
++nbTimersFired;
timers.unenroll(bar);
}
};
const bar = {
_onTimeout: function() {
++nbTimersFired;
timers.unenroll(foo);
}
};
timers.enroll(bar, 1);
timers._unrefActive(bar);
timers.enroll(foo, 1);
timers._unrefActive(foo);
setTimeout(function() {
assert.notStrictEqual(nbTimersFired, 2);
}, 20);

View File

@@ -1,30 +0,0 @@
'use strict';
// Regression test for https://github.com/nodejs/node-v0.x-archive/issues/8897.
// Test some private implementation details that should not be
// considered public interface.
const common = require('../common');
const timers = require('timers');
const foo = {
_onTimeout: common.mustNotCall('_onTimeout should not be called')
};
const bar = {
_onTimeout: common.mustCall(function() {
timers.unenroll(foo);
})
};
// We use timers with expiration times that are sufficiently apart to make
// sure that they're not fired at the same time on platforms where the timer
// resolution is a bit coarse (e.g Windows with a default resolution of ~15ms).
timers.enroll(bar, 1);
timers._unrefActive(bar);
timers.enroll(foo, 50);
timers._unrefActive(foo);
// Keep the process open.
setTimeout(() => {}, 100);