在受到 NoFlo.js 的启发后,我正在学习 highland.js。我希望能够让流递归操作。在这个人为的示例中,我将提供一个乘以 2 的数字,我们过滤结果 <= 512。一旦将数字相乘,它就会反馈到系统中。我的代码有效,但如果我在管道中取出 doto 函数,它不会处理任何数字。我怀疑我将数据错误地发送回 returnPipe。有没有更好的方法将数据传输回系统?我错过了什么?
###
input>--m--->multiplyBy2>---+
| |
| |
+---<returnPipe<----+
###
H = require('highland')
input = H([1])
returnPipe = H.pipeline(
H.doto((v)->console.log(v))
)
H.merge([input,returnPipe])
.map((v)-> return v * 2)
.filter((v)-> return v <= 512)
.pipe(returnPipe)