文档:Async hooks | Node.js v17.3.0 Documentation
1.简介
async_hooks模块提供了追踪异步资源的机制
createHook方法创建监听异步资源生命周期的钩子函数
所谓的异步资源指的是所有的异步操作,包含以下类型:
FSEVENTWRAP, FSREQCALLBACK, GETADDRINFOREQWRAP, GETNAMEINFOREQWRAP, HTTPINCOMINGMESSAGE,
HTTPCLIENTREQUEST, JSSTREAM, PIPECONNECTWRAP, PIPEWRAP, PROCESSWRAP, QUERYWRAP,
SHUTDOWNWRAP, SIGNALWRAP, STATWATCHER, TCPCONNECTWRAP, TCPSERVERWRAP, TCPWRAP,
TTYWRAP, UDPSENDWRAP, UDPWRAP, WRITEWRAP, ZLIB, SSLCONNECTION, PBKDF2REQUEST,
RANDOMBYTESREQUEST, TLSWRAP, Microtask, Timeout, Immediate, TickObject, PROMISE
2.executionAsyncId和triggerAsyncId
这里首先有两个重要的资源标识符
- executionAsyncId():获取当前异步操作执行id
- triggerAsyncId():获取触发当前异步操作的异步操作执行id
也就是说,如果a异
|