-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
async_hooks: reduce code duplication by using a factory #13755
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
58f011f
async_hooks: reduce duplication with factory
BridgeAR 4c00eee
async_hooks: add TODO entry
BridgeAR 8a8117e
rename factory
BridgeAR 8918fc8
address comment: use named functions
BridgeAR e4cd110
fixup func-style
BridgeAR 795358a
fixup rename function
BridgeAR fc397f8
fixup add comment about naming fn
BridgeAR 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
address comment: use named functions
- Loading branch information
commit 8918fc88481fbbf2a249c2f44cb4aca476103548
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -49,9 +49,9 @@ const init_symbol = Symbol('init'); | |
| const before_symbol = Symbol('before'); | ||
| const after_symbol = Symbol('after'); | ||
| const destroy_symbol = Symbol('destroy'); | ||
| const emitBeforeN = emitHookFactory(before_symbol); | ||
| const emitAfterN = emitHookFactory(after_symbol); | ||
| const emitDestroyN = emitHookFactory(destroy_symbol); | ||
| const emitBeforeN = emitHookFactory(before_symbol, 'emitBeforeN'); | ||
| const emitAfterN = emitHookFactory(after_symbol, 'emitAfterN'); | ||
| const emitDestroyN = emitHookFactory(destroy_symbol, 'emitDestroyN'); | ||
|
|
||
| // Setup the callbacks that node::AsyncWrap will call when there are hooks to | ||
| // process. They use the same functions as the JS embedder API. These callbacks | ||
|
|
@@ -345,10 +345,10 @@ function emitInitS(asyncId, type, triggerAsyncId, resource) { | |
| } | ||
| } | ||
|
|
||
| function emitHookFactory(symbol) { | ||
| function emitHookFactory(symbol, name) { | ||
| // Called from native. The asyncId stack handling is taken care of there | ||
| // before this is called. | ||
| return function(asyncId) { | ||
| const fn = function(asyncId) { | ||
| processing_hook = true; | ||
| // Use a single try/catch for all hook to avoid setting up one per | ||
| // iteration. | ||
|
|
@@ -367,6 +367,10 @@ function emitHookFactory(symbol) { | |
| restoreTmpHooks(); | ||
| } | ||
| }; | ||
| Object.defineProperty(fn, 'name', { | ||
|
Member
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. Mind leaving a comment that explains this sets the anonymous function name such it looks good in stack traces. |
||
| value: name | ||
| }); | ||
| return fn; | ||
| } | ||
|
|
||
|
|
||
|
|
||
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.
Could you change the
NtoNativewhile you are at it? That short naming convention really annoys me.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 guess in that case the the
Sshould also be renamed but I can't think of what it stands for right now. Does it stand forScript?