Skip to content

Commit 7c80f18

Browse files
committed
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 <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent afce912 commit 7c80f18

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
@@ -2368,6 +2368,38 @@ Type: Runtime
23682368
23692369
The `_stream_wrap` module is deprecated.
23702370
2371+
<a id="DEP0126"></a>
2372+
### DEP0126: timers.active()
2373+
<!-- YAML
2374+
changes:
2375+
- version: REPLACEME
2376+
pr-url: https://github.com/nodejs/node/pull/26760
2377+
description: Runtime deprecation.
2378+
-->
2379+
2380+
Type: Runtime
2381+
2382+
The previously undocumented `timers.active()` is deprecated.
2383+
Please use the publicly documented [`timeout.refresh()`][] instead.
2384+
If re-referencing the timeout is necessary, [`timeout.ref()`][] can be used
2385+
with no performance impact since Node.js 10.
2386+
2387+
<a id="DEP0127"></a>
2388+
### DEP0127: timers._unrefActive()
2389+
<!-- YAML
2390+
changes:
2391+
- version: REPLACEME
2392+
pr-url: https://github.com/nodejs/node/pull/26760
2393+
description: Runtime deprecation.
2394+
-->
2395+
2396+
Type: Runtime
2397+
2398+
The previously undocumented and "private" `timers._unrefActive()` is deprecated.
2399+
Please use the publicly documented [`timeout.refresh()`][] instead.
2400+
If unreferencing the timeout is necessary, [`timeout.unref()`][] can be used
2401+
with no performance impact since Node.js 10.
2402+
23712403
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
23722404
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
23732405
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
@@ -2423,6 +2455,9 @@ The `_stream_wrap` module is deprecated.
24232455
[`script.createCachedData()`]: vm.html#vm_script_createcacheddata
24242456
[`setInterval()`]: timers.html#timers_setinterval_callback_delay_args
24252457
[`setTimeout()`]: timers.html#timers_settimeout_callback_delay_args
2458+
[`timeout.ref()`]: timers.html#timers_timeout_ref
2459+
[`timeout.refresh()`]: timers.html#timers_timeout_refresh
2460+
[`timeout.unref()`]: timers.html#timers_timeout_unref
24262461
[`tls.CryptoStream`]: tls.html#tls_class_cryptostream
24272462
[`tls.SecureContext`]: tls.html#tls_tls_createsecurecontext_options
24282463
[`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)