async.series

Posted Tekkaman

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了async.series相关的知识,希望对你有一定的参考价值。

async.series

  

  series适用于顺序执行异步且前后无关联的调用。对于顺序执行异步且前后有叛逆的调用,则需要使用waterfall

  If any functions in the series pass an error to its callback, no more functions are run, andcallback is immediately called with the value of the error. Otherwise, callback receives an array of results when tasks have completed.

  

async.series([
    function(callback) {
        // do some stuff ...
        callback(null, \'one\');
    },
    function(callback) {
        // do some more stuff ...
        callback(null, \'two\');
    }
],
// optional callback
function(err, results) {
    // results is now equal to [\'one\', \'two\']
});

async.series({
    one: function(callback) {
        setTimeout(function() {
            callback(null, 1);
        }, 200);
    },
    two: function(callback){
        setTimeout(function() {
            callback(null, 2);
        }, 100);
    }
}, function(err, results) {
    // results is now equal to: {one: 1, two: 2}
});
View Code

 

参考:https://caolan.github.io/async/docs.html#series

以上是关于async.series的主要内容,如果未能解决你的问题,请参考以下文章