Skip to content

Commit b24e45a

Browse files
Fishrock123targos
authored andcommitted
timers: deprecate active() and _unrefActive()
Another nail in the coffin here, farewell ye ol C-style apis. These apis caused numerous other issues that required far too many safeguards. This gets us one step closer to not having to worry about those issues anymore. Refs: #18066 Refs: #20298 PR-URL: #26760 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 44450ef commit b24e45a

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

doc/api/deprecations.md

+35
Original file line numberDiff line numberDiff line change
@@ -2267,6 +2267,38 @@ undocumented `COUNTER_NET_SERVER_CONNECTION()`,
22672267
`COUNTER_HTTP_CLIENT_RESPONSE()` functions have been deprecated.
22682268
22692269
2270+
<a id="DEP0126"></a>
2271+
### DEP0126: timers.active()
2272+
<!-- YAML
2273+
changes:
2274+
- version: REPLACEME
2275+
pr-url: https://github.com/nodejs/node/pull/26760
2276+
description: Runtime deprecation.
2277+
-->
2278+
2279+
Type: Runtime
2280+
2281+
The previously undocumented `timers.active()` is deprecated.
2282+
Please use the publicly documented [`timeout.refresh()`][] instead.
2283+
If re-referencing the timeout is necessary, [`timeout.ref()`][] can be used
2284+
with no performance impact since Node.js 10.
2285+
2286+
<a id="DEP0127"></a>
2287+
### DEP0127: timers._unrefActive()
2288+
<!-- YAML
2289+
changes:
2290+
- version: REPLACEME
2291+
pr-url: https://github.com/nodejs/node/pull/26760
2292+
description: Runtime deprecation.
2293+
-->
2294+
2295+
Type: Runtime
2296+
2297+
The previously undocumented and "private" `timers._unrefActive()` is deprecated.
2298+
Please use the publicly documented [`timeout.refresh()`][] instead.
2299+
If unreferencing the timeout is necessary, [`timeout.unref()`][] can be used
2300+
with no performance impact since Node.js 10.
2301+
22702302
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
22712303
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
22722304
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
@@ -2322,6 +2354,9 @@ undocumented `COUNTER_NET_SERVER_CONNECTION()`,
23222354
[`script.createCachedData()`]: vm.html#vm_script_createcacheddata
23232355
[`setInterval()`]: timers.html#timers_setinterval_callback_delay_args
23242356
[`setTimeout()`]: timers.html#timers_settimeout_callback_delay_args
2357+
[`timeout.ref()`]: timers.html#timers_timeout_ref
2358+
[`timeout.refresh()`]: timers.html#timers_timeout_refresh
2359+
[`timeout.unref()`]: timers.html#timers_timeout_unref
23252360
[`tls.CryptoStream`]: tls.html#tls_class_cryptostream
23262361
[`tls.SecureContext`]: tls.html#tls_tls_createsecurecontext_options
23272362
[`tls.SecurePair`]: tls.html#tls_class_securepair

lib/timers.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,21 @@ function clearImmediate(immediate) {
304304
}
305305

306306
module.exports = {
307-
_unrefActive: unrefActive,
308-
active,
309307
setTimeout,
310308
clearTimeout,
311309
setImmediate,
312310
clearImmediate,
313311
setInterval,
314312
clearInterval,
313+
_unrefActive: deprecate(
314+
unrefActive,
315+
'timers._unrefActive() is deprecated.' +
316+
' Please use timeout.refresh() instead.',
317+
'DEP0127'),
318+
active: deprecate(
319+
active,
320+
'timers.active() is deprecated. Please use timeout.refresh() instead.',
321+
'DEP0126'),
315322
unenroll: deprecate(
316323
unenroll,
317324
'timers.unenroll() is deprecated. Please use clearTimeout instead.',

test/parallel/test-timers-max-duration-warning.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ process.on('warning', common.mustCall((warning) => {
1919
assert.strictEqual(lines[0], `${OVERFLOW} does not fit into a 32-bit signed` +
2020
' integer.');
2121
assert.strictEqual(lines.length, 2);
22-
}, 5));
22+
}, 6));
2323

2424

2525
{

0 commit comments

Comments
 (0)