如何在流编程中使用Highland.js的parallel()实现并行化?

时间:2018-10-17 13:14:52

标签: node.js parallel-processing stream-processing

我正在尝试在nodejs中实现流的并行化,以下代码终止于在管道中添加并行方法。

let x = [1,2,3,4,5] highland(x) .map(t => t*2) .parallel(2) .each(t => console.log(t)) .done(()=> console.log('DONE'))

错误:

Uncaught Error: Expected Stream, got number

使用highlandjs实现并行化的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

map创建单个流,但是parallel期望流的

请参见examples,第二个示例显示parallel的运行情况。您可以尝试修改该t=>t*2函数以在一个元素流中提供其结果:

t=>highland([x*2])

但这只是我脑海中的一个想法,我无法尝试。