dominictarr/pull-stream — pull request #20 by tounano (2014-07-05 15:15:57+00:00)
Title: If the source was faster than the sink, it was ending ahead of time...

Hey,

If the source was faster than the sink, `pull.highWaterMark` was ending ahead of time.

Example:

```js
var pull = require("pull-stream");

var delayedMap = function(d, done) {
setTimeout( function () {
done (null, d);
}, 1000)
}

pull(
pull.count(10),
pull.highWaterMark(7),
pull.asyncMap(delayedMap),
pull.log()
)
```

The reason that it happened is because there are 2 types of end:
1. When the source aborted
2. When the sink aborted

However, `highWaterMark` was marking both with the same variable `ended`. So if `highWaterMark` consumed everything from the source and it ended, it marked the stream as ended even though the sink didn't consume everything.

The way I solved it was by introducing a new variable `ending`. If the source reached it's end or had an error, this data would be recorded in `ending`. It will stop reading from the source.

`ended` will become `ending` once all the buffer is drained.