I am trying to achieve parallelization of streams in nodejs, Following code terminates on adding parallel method in the pipeline.
let x = [1,2,3,4,5]
highland(x)
.map(t => t*2)
.parallel(2)
.each(t => console.log(t))
.done(()=> console.log('DONE'))
ERROR :
Uncaught Error: Expected Stream, got number
What is the correct way of achieving parallelization by using highlandjs ?
map
creates a single stream, but parallel
expects a stream of streams.
See examples, the second one shows parallel
in action. You could try modifying that t=>t*2
function to provide its result in a one-element stream:
t=>highland([x*2])
but this is just an idea from the top of my head, I can not try it.