Yes, that might be it! I'll give that a try. Many thanks! On Monday, November 4, 2013 3:07:44 PM UTC+1, Floby wrote: > > is that what you are looking for ? > https://npmjs.org/package/stream-multiplexer > > On Saturday, 2 November 2013 00:38:52 UTC+1, Jan Van Ryswyck wrote: >> >> Hi all, >> >> I am still playing around with streams V2 and I was wondering whether it >> is possible to get the following example working somehow: >> >> var stream = require('stream'), >> util = require('util'); >> >> // >> // Reading stuff >> // >> >> var ReadingStuff = function() { >> this._data = [1, 2, 3, 4, 5]; >> this._readStreamIndex = 0; >> >> stream.Readable.call(this); >> }; >> >> util.inherits(ReadingStuff, stream.Readable); >> >> ReadingStuff.prototype._read = function() { >> if(this._readStreamIndex === this._data.length) { >> this._readStreamIndex = 0; >> this.push(null); >> return; >> } >> >> this.push(this._data[this._readStreamIndex].toString()); >> this._readStreamIndex += 1; >> }; >> >> >> // >> // Writing stuff >> // >> >> var WritingStuff = function() { >> stream.Writable.call(this); >> >> this.on('finish', function() { >> console.log('Finished writing stuff!!'); >> }); >> }; >> >> util.inherits(WritingStuff, stream.Writable); >> >> WritingStuff.prototype._write = function(chunk, encoding, next) { >> console.log(chunk.toString(encoding)); >> next(); >> }; >> >> // >> // Application >> // >> >> var readingStuff = new ReadingStuff(); >> >> var writingStuff = new WritingStuff(); >> var writingStuff2 = new WritingStuff(); >> >> readingStuff.pipe(writingStuff); >> >> process.nextTick(function() { >> // Just simulating another event loop >> readingStuff.pipe(writingStuff2); >> }); >> >> I havce a single read stream that I want to pipe to multiple write >> streams on separate iterations of the event loop (using process.nextTick to >> simulate that the read stream is used again later on). What I see is that >> the output is written to the first writable stream (+ the finish event is >> called). Afterwards on the finish event is executed for the second writable >> stream. Is it OK in this case to skip push(null) in the read stream? This >> means that there's no way to know inside the Writable stream that there's >> no more data to be wriitten. >> >> Is there a way to "reset" a readable stream? >> >>
-- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
