poelstra / ts-stream

Type-safe object streams with seamless support for backpressure, ending, and error handling
MIT License
65 stars 13 forks source link

Please connect the ended() promises of connected streams #7

Closed rogierschouten closed 9 years ago

rogierschouten commented 9 years ago

It is often handy to know at the reading side whether the end() has completed entirely, i.e. the end() promise has been resolved all the way back to the writer. To this end, it may be possible to connect the ended() method in such a way that it resolves to the ended() of the source.

poelstra commented 9 years ago

Basically, this would solve the second concern of https://github.com/poelstra/ts-stream/issues/2#issuecomment-110876701

poelstra commented 9 years ago

Fixed in 0.4.1, by using the second argument to end().

This is now already supported by map() and filter().

If you want to support it in your own transforms, use it like:

(readable, writable) => {
    readable.forEach(
        (v) => ...,
        (err) => writable.end(err, readable.ended())
    );
}
poelstra commented 9 years ago

Btw, it may be a good idea that I rename ended() to e.g. result() in the near future, as it may be a bit confusing now that the promise returned by ended() resolves a lot later than that of end().

rogierschouten commented 9 years ago

I don't have a strong opinion, 'result' sounds good too

poelstra commented 9 years ago

Renamed to result() in 0.5.1.