Skip to content

Commit

Permalink
stream: notify user of to pipe state via 'unpipe' event.
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed Jul 27, 2012
1 parent f692347 commit bc1e02c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/stream.js
Expand Up @@ -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);
Expand All @@ -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);

This comment has been minimized.

Copy link
@isaacs

isaacs Jul 30, 2012

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

This comment has been minimized.

Copy link
@dominictarr

dominictarr Jul 30, 2012

Author Owner

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.


// Allow for unix-like usage: A.pipe(B).pipe(C)
return dest;
Expand Down

0 comments on commit bc1e02c

Please sign in to comment.