-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
timers: add hasRef method to Timeout & Immediate #20898
Conversation
Provide a way to check whether the current timer or immediate is refed.
dac0830
to
ebb23e4
Compare
@@ -23,6 +23,16 @@ running as long as the immediate is active. The `Immediate` object returned by | |||
[`setImmediate()`][] exports both `immediate.ref()` and `immediate.unref()` | |||
functions that can be used to control this default behavior. | |||
|
|||
### immediate.hasRef() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... maybe isRef()
? hasRef
just seems... awkward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isRefed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasRef
matches the HandleWrap, hence that choice. Open to other names if there's a consensus.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really mind what is chosen
@@ -23,6 +23,16 @@ running as long as the immediate is active. The `Immediate` object returned by | |||
[`setImmediate()`][] exports both `immediate.ref()` and `immediate.unref()` | |||
functions that can be used to control this default behavior. | |||
|
|||
### immediate.hasRef() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isRefed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a few nits.
doc/api/timers.md
Outdated
|
||
* Returns: {boolean} | ||
|
||
Used to check whether the `Immediate` object will keep the Node.js event loop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe replace "Used to check whether ..." with "If true, ..."
doc/api/timers.md
Outdated
|
||
* Returns: {boolean} | ||
|
||
Used to check whether the `Timeout` object will keep the Node.js event loop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here.
const assert = require('assert'); | ||
|
||
const immediate = setImmediate(() => {}); | ||
assert(immediate.hasRef()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use assert.strictEqual()
in these tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really mind what name it gets, personally.
Landed in 48a2568 |
Provide a way to check whether the current timer or immediate is refed. PR-URL: #20898 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Provide a way to check whether the current timer or immediate is refed. This was done as per request from @Fishrock123 due to the removal of _handle from unrefed timers.
The method name was chosen to match what used to be available on the
_handle
— unlike a getter it should also make it clear that it's not possible to change it by trying to assign.(Since it depends on a
semver-major
PR, I'm labeling this as such too.)Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes