Tekkaman

导航

 

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

posted on   Tekkaman  阅读(958)  评论(0编辑  收藏  举报
努力加载评论中...
 
点击右上角即可分享
微信分享提示