From b24e45ab8dbb0b385888f4de9163b5bf50d4092c Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Mon, 18 Mar 2019 15:56:49 -0700 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/18066 Refs: https://github.com/nodejs/node/pull/20298 PR-URL: https://github.com/nodejs/node/pull/26760 Reviewed-By: Ruben Bridgewater Reviewed-By: Anatoli Papirovski Reviewed-By: Matteo Collina Reviewed-By: Joyee Cheung --- doc/api/deprecations.md | 35 +++++++++++++++++++ lib/timers.js | 11 ++++-- .../test-timers-max-duration-warning.js | 2 +- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 20ef6ad7169d64..4e68e2e46157c8 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2267,6 +2267,38 @@ undocumented `COUNTER_NET_SERVER_CONNECTION()`, `COUNTER_HTTP_CLIENT_RESPONSE()` functions have been deprecated. + +### DEP0126: timers.active() + + +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. + + +### DEP0127: timers._unrefActive() + + +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 @@ -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 diff --git a/lib/timers.js b/lib/timers.js index e9486edc5386fb..8a16532bd5def4 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -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.', diff --git a/test/parallel/test-timers-max-duration-warning.js b/test/parallel/test-timers-max-duration-warning.js index c978cf29c3fe4d..a104c1700db81d 100644 --- a/test/parallel/test-timers-max-duration-warning.js +++ b/test/parallel/test-timers-max-duration-warning.js @@ -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)); {