Andrey Pechkurov
1 min readMar 1, 2019

--

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

--

--

Andrey Pechkurov
Andrey Pechkurov

Written by Andrey Pechkurov

Core database engineer at QuestDB. Distributed systems gazer. Node.js contributor. Occasional tech blogger and speaker.

Responses (1)