阿西河

所有教程

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

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js async_hooks.executionAsyncId()

      Node.js async_hooks.executionAsyncId() 版本历史

      Returns: < number> The asyncId of the current execution context. Useful to track when something calls.

      const async_hooks = require('async_hooks');
      
      console.log(async_hooks.executionAsyncId());  // 1 - bootstrap
      fs.open(path, 'r', (err, fd) => {
        console.log(async_hooks.executionAsyncId());  // 6 - open()
      });
      

      The ID returned from executionAsyncId() is related to execution timing, not causality (which is covered by triggerAsyncId()):

      const server = net.createServer((conn) => {
        // Returns the ID of the server, not of the new connection, because the
        // callback runs in the execution scope of the server's MakeCallback().
        async_hooks.executionAsyncId();
      
      }).listen(port, () => {
        // Returns the ID of a TickObject (i.e. process.nextTick()) because all
        // callbacks passed to .listen() are wrapped in a nextTick().
        async_hooks.executionAsyncId();
      });
      

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


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


      目录
      本文目录
      目录