The only meaningful way to exactly match async hook callback with an async resource instance, e.g. a promise object, that I know of, is to use executionAsyncId()
function in async resource’s code:
But then you would have to deal with Async Hooks API everywhere in your code, which kills the whole idea of single configuration point.
As a workaround, you may try to use resource
argument of the destroy
callback. For promises it will be a PromiseWrap
object that has the promise
property with the promise instance itself. See the doc:
https://nodejs.org/api/async_hooks.html#async_hooks_resource