Closed Jeff-Lewis closed 8 years ago
The parentId
for NextTickerWrap
is supposed to be null
. In the final version of AsyncWrap
that will also be the case.
This is because parentId
is only set when a handle was directly created as a result of a another handle. Most popular example is a TCP server (parent) creating a TCP socket (child). The much more normal case is that some JavaScript code invoked for example nextTick
and that way created a handle object. In this case the handle was created from a callback execution and not another handle.
The standard pattern for tracking the parent is:
currentId
) for the currently executing callback using the pre
and post
hooks.init
hook use parent = parentId === null ? currentId : parentId
.example: https://github.com/AndreasMadsen/trace/blob/master/trace.js#L49 documentation: https://github.com/nodejs/diagnostics/tree/master/tracing/AsyncWrap#parentuid
Hi, I'm experimenting with creating a version of CLS that uses
async-hook
andAsyncWrap
instead of the olderAsyncListener
and it appears that it very rarely sees parentIds in the init hook.Is this b/c of NextTickerWrap doesn't pass them? Is there an alternate way to wrap
nextTick
to include it?