首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何同步2 async.waterfalls

如何同步2 async.waterfalls
EN

Stack Overflow用户
提问于 2013-12-18 00:44:45
回答 2查看 593关注 0票数 0

我有一组必须按顺序读取的命令。任何故障,处理停止。

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条目完全不同,所以很难将它们组合起来。但是,在我去下一个瀑布之前,我要完成第一个瀑布。我如何从现有的两个瀑布中制造一个“瀑布”?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-18 02:07:43

只要将两个数组组合在一起,它们就会按顺序运行:

代码语言:javascript
复制
async.waterfall(readCommands.concat(writeCommands), function(err) {...}
票数 2
EN

Stack Overflow用户

发布于 2013-12-18 00:57:26

听起来很疯狂,但实际上可以嵌套这些异步方法:

代码语言:javascript
复制
async.series([
  function (done) {
    async.waterfall(readCommands, done);
  },
  function (done) {
    async.waterfall(writeCommands, done);
  }
], function (err) {
  // All done
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20647652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档