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

async.waterfall

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

标签:tar   dia   strong   imm   called   ext   show   html   main   

async.waterfall

  if any of the tasks pass an error to their own callback, the next function is not executed, and the main callback is immediately called with the error.

技术分享
async.waterfall([
    function(callback) {
        callback(null, ‘one‘, ‘two‘);
    },
    function(arg1, arg2, callback) {
        // arg1 now equals ‘one‘ and arg2 now equals ‘two‘
        callback(null, ‘three‘);
    },
    function(arg1, callback) {
        // arg1 now equals ‘three‘
        callback(null, ‘done‘);
    }
], function (err, result) {
    // result now equals ‘done‘
});
View Code
技术分享
// Or, with named functions:
async.waterfall([
    myFirstFunction,
    mySecondFunction,
    myLastFunction,
], function (err, result) {
    // result now equals ‘done‘
});
function myFirstFunction(callback) {
    callback(null, ‘one‘, ‘two‘);
}
function mySecondFunction(arg1, arg2, callback) {
    // arg1 now equals ‘one‘ and arg2 now equals ‘two‘
    callback(null, ‘three‘);
}
function myLastFunction(arg1, callback) {
    // arg1 now equals ‘three‘
    callback(null, ‘done‘);
}
View Code

 

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

async.waterfall

标签:tar   dia   strong   imm   called   ext   show   html   main   

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

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