Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit bc1e02c4448064932bf05edaf67935c5fa4c10c7 1 parent f692347
@dominictarr authored
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/stream.js
View
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
isaacs added a note

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

@dominictarr 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.

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;
@isaacs

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

@dominictarr

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.

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