-
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
process: code cleanup for nextTick #28047
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1a66c0d
process: code cleanup for nextTick
apapirovski 8c8c730
fixup: add destroy hook test
apapirovski c5c3c6f
fixup: add comment explaining the test
apapirovski 20f2a93
fixup: make test work in workers
apapirovski 83658f7
fixup: typo
apapirovski 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const async_hooks = require('async_hooks'); | ||
|
||
// Checks that enabling async hooks in a callback actually | ||
// triggers after & destroy as expected. | ||
|
||
const fnsToTest = [setTimeout, (cb) => { | ||
setImmediate(() => { | ||
cb(); | ||
|
||
// We need to keep the event loop open for this to actually work | ||
// since destroy hooks are triggered in unrefed Immediates | ||
setImmediate(() => { | ||
hook.disable(); | ||
}); | ||
}); | ||
}, (cb) => { | ||
process.nextTick(() => { | ||
cb(); | ||
|
||
// We need to keep the event loop open for this to actually work | ||
// since destroy hooks are triggered in unrefed Immediates | ||
setImmediate(() => { | ||
hook.disable(); | ||
assert.strictEqual(fnsToTest.length, 0); | ||
}); | ||
}); | ||
}]; | ||
|
||
const hook = async_hooks.createHook({ | ||
before: common.mustNotCall(), | ||
after: common.mustCall(() => {}, 3), | ||
destroy: common.mustCall(() => { | ||
hook.disable(); | ||
nextTest(); | ||
}, 3) | ||
}); | ||
|
||
nextTest(); | ||
|
||
function nextTest() { | ||
if (fnsToTest.length > 0) { | ||
fnsToTest.shift()(common.mustCall(() => { | ||
hook.enable(); | ||
})); | ||
} | ||
} |
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.
On a side note, I wonder if it make sense now to just merge
process/promises.js
andprocess/task_queues.js
- the latter is currently the only one who requires the former.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? At the same time it's a little easier to read the task queue code as is. Also, the code in promises isn't really explicitly tied to task queues.
If someone feels strongly, they should open a PR. I, personally, like it as is.
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.
Keep in mind, more files = more startup time.
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.
@Fishrock123 This is now somewhat negligible since we have shipped pre-built code cache for builtin modules, which eliminates the majority of the overhead of loading an builtin module (compilation) - of course that does not apply to modules like
internal/errors.js
which does a lot of stuff in the initialization, but that overhead would be eliminated as well when the v8 snapshot integration is completed.