joyent/node — pull request #3778 by dominictarr (2012-07-27 15:46:50+00:00)
Title: stream: propagate 'error' and 'close' to destroy(), in both directions.

I'm making this pull request mainly for the pourpose of discussion.

Propagate the termination of a stream to the rest of the pipeline.
In node 0.8.4, emitting 'error' or 'close' events terminates the stream.
All listeners are cleaned up, so no more data will be passed.

However, the rest of the pipeline needs to be notified of this,
so that it can dispose of it's resources. in 0.8.4,
`source.emit('close') ---> dest.destroy()` I have extended this pattern:

``` js
source.emit('close') ----> dest.destroy()
source.emit('error') ----> dest.destroy()
dest.emit('close') ------> source.destroy()
dest.emit('error') ------> source.destroy()
```

notice that the 'close' and 'error' listeners are nearly identical.
it may be worth merging them into a single event?