Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Async Map with Highland.js

I have a Highland stream that is periodically getting data from a server. I need to do a database lookup inside of a map. I can't find any mention of doing anything async in any of Highland's transformers.

like image 425
giodamelio Avatar asked Sep 29 '22 03:09

giodamelio


1 Answers

You can use consume to process a stream in an async manner.

_([1, 2, 3, 4]).consume(function(err, item, push, next) {
  // Do fancy async thing
  setImmediate(function() {
    // Push the number onto the new stream
    push(null, item);

    // Consume the next item
    next();
  });
})).toArray(function(items) {
  console.log(items); // [1, 2, 3, 4]
});
like image 71
giodamelio Avatar answered Oct 07 '22 00:10

giodamelio