1.0.0 • Published 9 years ago
thor-stream v1.0.0
thor-stream
Unended Stream, useful for piping streams one after another
doc
thorStream(onWrite, onEnd, options) ⇒ stream
Creates a writable and readable stream
Kind: global function
Returns: stream - a simplified stream
Param | Type | Description |
---|---|---|
onWrite | function | callback on data |
onEnd | function | callback on end |
options | object | setting autoDestroy will destory stream once stream ended defaults to true, setting thorMode will keep the stream stay long :iywim: |
usage
var urls = ['http://x', 'http://y'];
function requestUrl(scrollId, stream) {
var url = 'http:// sss' + scrollId;
return request(url)
.pipe(JSONStream.parse('hits.hits.*'))
.pipe(stream);
}
var stream = thorStream(function write(data) {
count++;
this.emit('data', data);
},
function end () {
//ending the stream if no data received for this
if(count === 0) {
this.endThor();
this.emit('end');
return;
}
count = 0;
requestUrl(scrollId, stream);
});
1.0.0
9 years ago