crap. that is terrible. don't use next tick. i wish i could edit the post. 
do this:

reader1.once('end', function () {
  reader2.pipe(writer)
})
reader1.pipe(writer, {end: false})

the difference is that the read streams will pipe consecutively. if you 
want them to pipe concurrently, you'll have to do do `writer.end()` after 
all the readers emit an `end` event. in other words, you would have to do 
control flow.

On Saturday, October 26, 2013 3:43:33 PM UTC-7, Jonathan Ong wrote:
>
> the read stream #1 will end the write stream when it is done. you don't 
> want want that to happen. you'll want to `writingStuff.end()` yourself (not 
> specifically this case, but in general, since the read stream #1 could take 
> longer than #2):
>
> reader1.pipe(writer, {end: false})
>
> process.nextTick(function () {
>   reader2.pipe(writer, {end: false})
>   
>   reader2.once('end', function () {
>     writer.end()
>   })
> })
>
> On Saturday, October 26, 2013 2:23:24 PM UTC-7, Jan Van Ryswyck wrote:
>>
>> Hi all,
>>
>> I am playing around with streams V2 and I was wondering whether it is 
>> possible to get the following example working somehow:
>>
>> //
>> // Reading stuff
>> //
>>
>> var ReadingStuff = function() {
>> this._data = [1, 2, 3, 4, 5];
>>
>> stream.Readable.call(this);
>> };
>>
>> util.inherits(ReadingStuff, stream.Readable);
>>
>> ReadingStuff.prototype._read = function() {
>> if(0 === this._data.length) {
>> this.push(null);
>> return;
>> }
>>
>> this.push(this._data[0].toString());
>> this._data.shift();
>> };
>>
>>
>> //
>> // 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();
>>
>> readingStuff.pipe(writingStuff);
>>
>> process.nextTick(function() {
>> var readingStuff2 = new ReadingStuff();
>> readingStuff2.pipe(writingStuff); 
>> });
>>
>>
>> I have two different read streams that I want to pipe to a single write 
>> stream on separate iterations of the event loop (suppose I implement the 
>> write stream as a singleton in my application). What I see is that the 
>> output of the first read stream is written to the write stream and when it 
>> is done, the 'finish' event is called. The output of the second stream is 
>> completely ignored. 
>>
>> Is there a way to write the output of the second read stream to the write 
>> 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.

Reply via email to