阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js async_hooks.triggerAsyncId()

      Node.js async_hooks.triggerAsyncId()

      • Returns: < number> The ID of the resource responsible for calling the callback that is currently being executed.
      const server = net.createServer((conn) => {
        // The resource that caused (or triggered) this callback to be called
        // was that of the new connection. Thus the return value of triggerAsyncId()
        // is the asyncId of "conn".
        async_hooks.triggerAsyncId();
      
      }).listen(port, () => {
        // Even though all callbacks passed to .listen() are wrapped in a nextTick()
        // the callback itself exists because the call to the server's .listen()
        // was made. So the return value would be the ID of the server.
        async_hooks.triggerAsyncId();
      });
      

      Note that promise contexts may not get valid triggerAsyncIds by default. See the section on promise execution tracking.


      更多选项请参考:Node.js 异步钩子,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录