-
Notifications
You must be signed in to change notification settings - Fork 30k
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
async_hooks: cleanup emitBefore and emitAfter in timers and nextTick #14050
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,13 +34,10 @@ const kOnTimeout = TimerWrap.kOnTimeout | 0; | |
const initTriggerId = async_hooks.initTriggerId; | ||
// Two arrays that share state between C++ and JS. | ||
const { async_hook_fields, async_uid_fields } = async_wrap; | ||
// Used to change the state of the async id stack. | ||
const { pushAsyncIds, popAsyncIds } = async_wrap; | ||
// The needed emit*() functions. | ||
const { emitInit, emitBefore, emitAfter, emitDestroy } = async_hooks; | ||
// Grab the constants necessary for working with internal arrays. | ||
const { kInit, kBefore, kAfter, kDestroy, kAsyncUidCntr } = | ||
async_wrap.constants; | ||
const { kInit, kDestroy, kAsyncUidCntr } = async_wrap.constants; | ||
// Symbols for storing async id state. | ||
const async_id_symbol = Symbol('asyncId'); | ||
const trigger_id_symbol = Symbol('triggerAsyncId'); | ||
|
@@ -149,22 +146,6 @@ exports._unrefActive = function(item) { | |
}; | ||
|
||
|
||
function timerEmitBefore(asyncId, triggerAsyncId) { | ||
if (async_hook_fields[kBefore] > 0) | ||
emitBefore(asyncId, triggerAsyncId); | ||
else | ||
pushAsyncIds(asyncId, triggerAsyncId); | ||
} | ||
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. Reason these were here is for the same reason explained in nextTick. |
||
|
||
|
||
function timerEmitAfter(asyncId) { | ||
if (async_hook_fields[kAfter] > 0) | ||
emitAfter(asyncId); | ||
else | ||
popAsyncIds(asyncId); | ||
} | ||
|
||
|
||
// The underlying logic for scheduling or re-scheduling a timer. | ||
// | ||
// Appends a timer onto the end of an existing timers list, or creates a new | ||
|
@@ -318,14 +299,14 @@ function tryOnTimeout(timer, list) { | |
timer[async_id_symbol] : null; | ||
var threw = true; | ||
if (timerAsyncId !== null) | ||
timerEmitBefore(timerAsyncId, timer[trigger_id_symbol]); | ||
emitBefore(timerAsyncId, timer[trigger_id_symbol]); | ||
try { | ||
ontimeout(timer); | ||
threw = false; | ||
} finally { | ||
if (timerAsyncId !== null) { | ||
if (!threw) | ||
timerEmitAfter(timerAsyncId); | ||
emitAfter(timerAsyncId); | ||
if (!timer._repeat && async_hook_fields[kDestroy] > 0 && | ||
!timer._destroyed) { | ||
emitDestroy(timerAsyncId); | ||
|
@@ -756,7 +737,7 @@ function processImmediate() { | |
// 4.7) what is in this smaller function. | ||
function tryOnImmediate(immediate, oldTail) { | ||
var threw = true; | ||
timerEmitBefore(immediate[async_id_symbol], immediate[trigger_id_symbol]); | ||
emitBefore(immediate[async_id_symbol], immediate[trigger_id_symbol]); | ||
try { | ||
// make the actual call outside the try/catch to allow it to be optimized | ||
runCallback(immediate); | ||
|
@@ -765,7 +746,7 @@ function tryOnImmediate(immediate, oldTail) { | |
// clearImmediate checks _callback === null for kDestroy hooks. | ||
immediate._callback = null; | ||
if (!threw) | ||
timerEmitAfter(immediate[async_id_symbol]); | ||
emitAfter(immediate[async_id_symbol]); | ||
if (async_hook_fields[kDestroy] > 0 && !immediate._destroyed) { | ||
emitDestroy(immediate[async_id_symbol]); | ||
immediate._destroyed = true; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
History lesson: This was introduced originally because of a crazy method to keep track of the id stack. Which was a lot faster than it is currently, but added an obscene amount of complexity. I hope to simplify that approach in the future and reintroduce it, but seems I overlooked these calls can be removed for the time being.