-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
|
||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more. Maybe replace "Used to check whether ..." with "If true, ..." |
||
active. | ||
|
||
### immediate.ref() | ||
<!-- YAML | ||
added: v9.7.0 | ||
|
@@ -61,6 +71,16 @@ timer is active. Each of the `Timeout` objects returned by these functions | |
export both `timeout.ref()` and `timeout.unref()` functions that can be used to | ||
control this default behavior. | ||
|
||
### timeout.hasRef() | ||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
|
||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here. |
||
active. | ||
|
||
### timeout.ref() | ||
<!-- YAML | ||
added: v0.9.1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,14 @@ | |
const common = require('../common'); | ||
const Countdown = require('../common/countdown'); | ||
|
||
const assert = require('assert'); | ||
|
||
const immediate = setImmediate(() => {}); | ||
assert(immediate.hasRef()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use |
||
immediate.unref(); | ||
assert(!immediate.hasRef()); | ||
clearImmediate(immediate); | ||
|
||
// This immediate should execute as it was unrefed and refed again. | ||
// It also confirms that unref/ref are chainable. | ||
setImmediate(common.mustCall(firstStep)).ref().unref().unref().ref(); | ||
|
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