What is the best way to create a readable stream from array and channel values ββinto a writable stream? I saw a substack example using setInterval, and I can implement this successfully using 0 for the interval value, but I repeat a lot of data and running gc slows down every time.
// Working with the setInterval wrapper var arr = [1, 5, 3, 6, 8, 9]; function createStream () { var t = new stream; t.readable = true; var times = 0; var iv = setInterval(function () { t.emit('data', arr[times]); if (++times === arr.length) { t.emit('end'); clearInterval(iv); } } }, 0); // Create the writable stream s // .... createStream().pipe(s);
What I would like to do is emit values ββwithout setInterval. Perhaps using such an asynchronous module:
async.forEachSeries(arr, function(item, cb) { t.emit('data', item); cb(); }, function(err) { if (err) { console.log(err); } t.emit('end'); });
In this case, I iterate over the array and emit data, but never translate any values. I already saw the shinout ArrayStream , but I think it was created before v0.10, and that is a bit more overhead than I'm looking for.
Tankofvines
source share