-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Open
Labels
async_hooksIssues and PRs related to the async hooks subsystem.Issues and PRs related to the async hooks subsystem.docIssues and PRs related to the documentations.Issues and PRs related to the documentations.
Description
Affected URL(s)
https://nodejs.org/api/async_hooks.html#async-hooks
Description of the problem
I am not sure how I would accomplish the tracking of un-resolved async functions in this testing tool https://github.com/anywhichway/benchtest, without async_hooks
in any kind of simple manner. The Node docs request the submission of a use case for async_hooks
since the API is not recommended.
Currently the tool only requires a few lines of code:
const asyncTracker = new Map(),
asyncHook = async_hooks.createHook({
init: (asyncId, type, triggerAsyncId, resource) => {
asyncTracker.set(asyncId,{type,triggerAsyncId,resource})
},
destroy: asyncId => {
asyncTracker.delete(asyncId);
},
promiseResolve: asyncId => {
asyncTracker.delete(asyncId);
},
}),
trackAsync = (on) => {
if(on) {
if(!asyncTracker.enabled) {
asyncTracker.clear();
asyncHook.enable();
}
} else if(!on && asyncTracker.enabled){
asyncHook.disable();
}
asyncTracker.enabled = on;
};
mcollina, vdeturckheim, kenrick95, benjamingr and thantos
Metadata
Metadata
Assignees
Labels
async_hooksIssues and PRs related to the async hooks subsystem.Issues and PRs related to the async hooks subsystem.docIssues and PRs related to the documentations.Issues and PRs related to the documentations.