我有一组必须按顺序读取的命令。任何故障,处理停止。
readCommands是一个读取函数数组..。
async.waterfall(readCommands,function){ if (err) { console.log(err);res.send(500,{ error : err.toString() });
在这一点上,我知道我是怎么开始的。现在我要执行写命令
async.waterfall(writeCommands,function){ if (err) { console.log(err);res.send(500,{ error : err.toString() });
数组readCommands和writeCommands条目完全不同,所以很难将它们组合起来。但是,在我去下一个瀑布之前,我要完成第一个瀑布。我如何从现有的两个瀑布中制造一个“瀑布”?
发布于 2013-12-18 02:07:43
只要将两个数组组合在一起,它们就会按顺序运行:
async.waterfall(readCommands.concat(writeCommands), function(err) {...}发布于 2013-12-18 00:57:26
听起来很疯狂,但实际上可以嵌套这些异步方法:
async.series([
function (done) {
async.waterfall(readCommands, done);
},
function (done) {
async.waterfall(writeCommands, done);
}
], function (err) {
// All done
});https://stackoverflow.com/questions/20647652
复制相似问题