javascript - 异步库是否有任何用于处理管道的控制流?

标签 javascript pipeline async.js

我正在查看 async库,但我似乎找不到处理管道的控制流。我只是想知道我是否在这里遗漏了一些东西。

我想实现一个管道。示例:

let pipeline = [];
pipeline.push((input, next) => { next(null, input); });
pipeline.push((input, next) => { next(null, input); });
var pipelineResult = pipelineRunner.run(pipeline, 'sample input', (error, result) => {});

说明:调用一系列函数。每个函数接收一个input 和一个next 函数。每个函数都会处理输入,并将其作为参数传递给next 函数。作为管道执行的结果,我得到了已处理的输入,或者,如果任何函数调用 next 时出现错误,管道将停止并调用回调。

我想这是一个非常常见的用例,所以我认为 async可以做到,但我找不到它。如果您知道任何其他库可以实现这样的结果,那也是可以接受的。

最佳答案

您正在寻找async.waterfall function .

或者您可以apply asyc.seqasync.compose如果您需要一个可以传递初始输入的函数,则可以使用多个参数。

关于javascript - 异步库是否有任何用于处理管道的控制流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34145402/

相关文章:

javascript - Lazyload polyfill/Magneto 2 js 错误 "loading-attribute-polyfill.js Uncaught ReferenceError: module is not defined"

javascript - 打开/关闭鼠标悬停时显示的标题

computer-science - 迭代器 vs.重复

javascript - async.js : async. eachSeries 结果总是抛出未定义

node.js - 选择适当的异步方法来进行最大请求数/秒的批处理

javascript - 无法在 Angular js 中的 .run 中注入(inject)服务

javascript - 如何向 eslint 规则添加异常(exception)?

python - 包括 Scaling 和 PCA 作为 GridSearchCV 的参数

elasticsearch - 通过子聚合进行Elasticsearch流水线

python - 在django中,mergemigrations和squashmigrations有什么区别?