Skip to content
Browse files

stream: notify user of to pipe state via 'unpipe' event.

  • Loading branch information...
1 parent f692347 commit bc1e02c4448064932bf05edaf67935c5fa4c10c7 @dominictarr committed Jul 28, 2012
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/stream.js
4 lib/stream.js
@@ -101,6 +101,8 @@ Stream.prototype.pipe = function(dest, options) {
dest.removeListener('end', cleanup);
dest.removeListener('close', cleanup);
+ source.emit('unpipe', dest);
source.on('end', cleanup);
@@ -109,7 +111,7 @@ Stream.prototype.pipe = function(dest, options) {
dest.on('end', cleanup);
dest.on('close', cleanup);
- dest.emit('pipe', source);
+ dest.emit('pipe', source, cleanup);
isaacs added a note Jul 30, 2012

Why is the cleanup function passed to the dest's pipe event?

dominictarr added a note Jul 30, 2012

so that the dest can trigger the unpipe if it so wishes.
it's probably gonna be the dest that needs to do so, because say, the dest has errored.
although, with a tee pipe, in the new api, you could maybe pass the particular dest to source.unpipe(dest)

the most useful case for this would be piping some thing to multiple places, for redundancy, expecting some to possibly
fail. hmm, I think this is a sufficiently rare use case to justify a userland stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
// Allow for unix-like usage: A.pipe(B).pipe(C)
return dest;

0 comments on commit bc1e02c

Please sign in to comment.
Something went wrong with that request. Please try again.