async-through
Readable stream that ensures that onend is only called once no ondata items are pending, thus supporting async operations inside ondata.
var asyncThru = var from = ;var stream = ; { ;} { // this === stream, so the below also works: // this.queue(null); stream;} ;
2
6
8
10
stream ended
onend
is optional
var from = ; // onend is optionalvar stream = ; { ;} ;
one to many
var stream = ; { ;} ;
2
0.5
4
1
6
1.5
stream ended
Installation
npm install async-through
API
asyncThrough(ondata, onend)
/**
* Returns a stream that works just like a normal through stream except that it keeps track of pending items that are
* being processed inside the `ondata` function.
* This allows the processing code to be async yet ensures that `onend` doesn't get called until no items are pending.
*
* @name exports
* @function
* @param ondata_ {Function} function (data) { .. } to process data item and queue the result
* @param onend_ {Function} (optional) function () { .. }
* @return {Stream} async-through stream
*/
one-to-many
If you want to queue
multiple results per incoming item, do so by providing true
as the second paramater to queue
in order to signal that more results for this item are coming.
stream;stream;stream;stream;
License
MIT