Skip to content

Commit

Permalink
timers: deprecate active() and _unrefActive()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Fishrock123 authored and targos committed Mar 30, 2019
1 parent 44450ef commit b24e45a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
35 changes: 35 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2267,6 +2267,38 @@ undocumented `COUNTER_NET_SERVER_CONNECTION()`,
`COUNTER_HTTP_CLIENT_RESPONSE()` functions have been deprecated.
<a id="DEP0126"></a>
### DEP0126: timers.active()
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/26760
description: Runtime deprecation.
-->
Type: Runtime
The previously undocumented `timers.active()` is deprecated.
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.
<a id="DEP0127"></a>
### DEP0127: timers._unrefActive()
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/26760
description: Runtime deprecation.
-->
Type: Runtime
The previously undocumented and "private" `timers._unrefActive()` is deprecated.
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.
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array
Expand Down Expand Up @@ -2322,6 +2354,9 @@ undocumented `COUNTER_NET_SERVER_CONNECTION()`,
[`script.createCachedData()`]: vm.html#vm_script_createcacheddata
[`setInterval()`]: timers.html#timers_setinterval_callback_delay_args
[`setTimeout()`]: timers.html#timers_settimeout_callback_delay_args
[`timeout.ref()`]: timers.html#timers_timeout_ref
[`timeout.refresh()`]: timers.html#timers_timeout_refresh
[`timeout.unref()`]: timers.html#timers_timeout_unref
[`tls.CryptoStream`]: tls.html#tls_class_cryptostream
[`tls.SecureContext`]: tls.html#tls_tls_createsecurecontext_options
[`tls.SecurePair`]: tls.html#tls_class_securepair
Expand Down
11 changes: 9 additions & 2 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,21 @@ function clearImmediate(immediate) {
}

module.exports = {
_unrefActive: unrefActive,
active,
setTimeout,
clearTimeout,
setImmediate,
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.',
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-timers-max-duration-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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);
}, 5));
}, 6));


{
Expand Down

0 comments on commit b24e45a

Please sign in to comment.