码迷,mamicode.com
首页 > 其他好文 > 详细

async.series

时间:2017-09-07 18:15:58      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:color   height   idt   调用   nbsp   sed   called   sync   col   

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

标签:color   height   idt   调用   nbsp   sed   called   sync   col   

原文地址:http://www.cnblogs.com/tekkaman/p/7490771.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!