objectStream example
ahmadsholehin opened this issue · comments
Been trying to make objectStream
work:
// create a custom readable stream
const InputStream = function() {
Readable.call( this, { objectMode: true } );
this.currIndex = 0;
}
util.inherits( InputStream, Readable );
InputStream.prototype._read = function() {
// end stream after 5 items
if ( this.currIndex >= 5 )
return this.push( null );
// push json object into stream
this.push( { a: this.currIndex + 0, b: this.currIndex + 1 } );
this.currIndex++;
}
// feed readable stream to skale via objectStream
const sc = skale.context();
const inputStream = new InputStream();
sc.objectStream( inputStream )
.collect( ( err, res ) => {
console.log( res );
sc.end();
} );
The input stream works, but couldn't get skale to output anything. Is this the correct way to use objectStream
?