阿西河

所有教程

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

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js domain.bind

      Node.js domain.bind(callback)

      • callback < Function> The callback function
      • Returns: < Function> The bound function

      The returned function will be a wrapper around the supplied callback function. When the returned function is called, any errors that are thrown will be routed to the domain’s ‘error’ event.

      const d = domain.create();
      
      function readSomeFile(filename, cb) {
        fs.readFile(filename, 'utf8', d.bind((er, data) => {
          // if this throws, it will also be passed to the domain
          return cb(er, data ? JSON.parse(data) : null);
        }));
      }
      
      d.on('error', (er) => {
        // an error occurred somewhere.
        // if we throw it now, it will crash the program
        // with the normal line number and stack message.
      });
      

      更多内容请参考:Node.js domain,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录