简体   繁体   中英

async.js how to repeat a series until an unexpected error occurs?

Is there a way to repeat a series of tasks until an unexpected error occurs in async.js ?

Something like this

async.series([
    function(callback) {
        // do stuff
    },
    function(callback) {
        // do more stuff
    },
    function(callback) {
        // do even more stuff
    },
    function(callback) {
        // more more more
    }
], function(error, results) {

    if(error.message.search(/ESOCKETTIMEDOUT|ETIMEDOUT/) == -1) {
        // stop here
    } else {
        // repeat series
    }
});

One possibility:

void function loop() {
  async.series([
      function(callback) {
          // do stuff
      },
      function(callback) {
          // do more stuff
      },
      function(callback) {
          // do even more stuff
      },
      function(callback) {
          // more more more
      }
  ], function(error, results) {
      if (error && error.message.search(/ESOCKETTIMEDOUT|ETIMEDOUT/) == -1) {
        // stop here
      } else {
        loop();
      }
  });
}();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM