You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 31, 2018. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 31, 2018. It is now read-only.
Once .end() is called, it can never be called again even if autoDestroy is false. #18
vares=require('event-stream');varmyThrough=es.through(null,function(){this.queue('(DONE)\n');});myThrough.autoDestroy=false;myThrough.pipe(process.stdout);varnoise1=es.through();noise1.pipe(myThrough);noise1.write('This is test #1.\n');noise1.end('Done #1!\n');varnoise2=es.through();noise2.pipe(myThrough);noise2.write('This is test #2.\n');noise2.end('Done #2!\n');console.log('All done.');
Because even though noise2 is piped to myThrough the stream no longer works once noise1.end() is called.
This is test #1.
Done #1!
(DONE)
All done.
By overwriting myThrough.end like this, calling noise1.end() doesn't "break" myThrough.
vares=require('event-stream');varmyThrough=es.through();myThrough.end=function(data){if(arguments.length){this.queue(data);}this.queue('(DONE)\n');this.writable=this.readable=true;// unsure if this is necessaryreturnthis;};myThrough.pipe(process.stdout);varnoise1=es.through();noise1.pipe(myThrough);noise1.write('This is test #1.\n');noise1.end('Done #1!\n');varnoise2=es.through();noise2.pipe(myThrough);noise2.write('This is test #2.\n');noise2.end('Done #2!\n');console.log('All done.');
Which outputs this:
This is test #1.
Done #1!
(DONE)
This is test #2.
Done #2!
(DONE)
All done.
In node@0.4 supported multisink pipes like this, but it was removed in 0.6, as it's a pretty rare edgecase.
If you want to have a stream that can do that, you should make it a new module.
In 0.4 it kept a count of the pipes that are currently flowing in, decrementing it when streams end,
and only calling end() when the last stream ends.
In my use-case, the myThrough pipe is going to be writing output (generated internally), but can also optionally read input to be muxed into its output. As such, the myThrough pipe should only close if ended explicitly. Does that make any sense?
Well, there is probably the odd case where you might want to do that.
Overwriting the end method would like you have done here is probably the way I'd do it too.
Activity
cowboy commentedon Jul 31, 2013
Here's a fairly simple example.
This doesn't work like I'd expect:
Because even though
noise2is piped tomyThroughthe stream no longer works oncenoise1.end()is called.By overwriting
myThrough.endlike this, callingnoise1.end()doesn't "break"myThrough.Which outputs this:
dominictarr commentedon Jul 31, 2013
In node@0.4 supported multisink pipes like this, but it was removed in 0.6, as it's a pretty rare edgecase.
If you want to have a stream that can do that, you should make it a new module.
In 0.4 it kept a count of the pipes that are currently flowing in, decrementing it when streams end,
and only calling
end()when the last stream ends.cowboy commentedon Jul 31, 2013
In my use-case, the
myThroughpipe is going to be writing output (generated internally), but can also optionally read input to be muxed into its output. As such, themyThroughpipe should only close if ended explicitly. Does that make any sense?dominictarr commentedon Jul 31, 2013
Well, there is probably the odd case where you might want to do that.
Overwriting the
endmethod would like you have done here is probably the way I'd do it too.