New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

es.fork #12

Closed
tblobaum opened this Issue Jul 13, 2012 · 2 comments

Comments

Projects
None yet
4 participants
@tblobaum

tblobaum commented Jul 13, 2012

I would like to be able to fork a stream so it can be piped to two places at the same time, is there an easy way to do this already? In consuming a stream I'd like to fork it one direction to save the data in a temporary place until the other fork has been successfully processed.

@Raynos

This comment has been minimized.

Contributor

Raynos commented Jul 13, 2012

stream.pipe(one)
stream.pipe(two)
@dominictarr

This comment has been minimized.

Owner

dominictarr commented Jul 13, 2012

the code you give here will just work, unless there is an error.

if you are worried about an error maybe you could do this:

stream.pipe(one)
stream.pipe(two)
one.removeAllListeners('error')
one.on('error', function () {
  //do what you gotta do.
  one.destroy() //cleanup one...
})

this will dump one but keep streaming to two. note: one must set writable=false just before it emits "error"

currently pipe always assigns an error listener, I've been wandering if that should be optional.
I'll be interesting to investigate your use-case to see if a good case can be made for optional error handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment