Re: [streams] getting and releasing reader (#297)

Thanks for bringing these up. I was actually just preparing a follow-up commit to the PR to propose a solution for these issues :). It is nice to have a new issue to discuss though.

> getReader() should succeed on closed stream

> getReader() should succeed on errored stream

Great justifications, agreed.

> Do we need auto-release?

Yes, I agree it is not as necessary anymore. We can probably remove it. The change in behavior between auto-release and manual release only impacts a few minor cases.

But on the other hand, I am not sure what the downsides of auto-release are, if any. So maybe we should more carefully consider what the changes in behavior are and which result we would prefer.

> Do we need .closed in stream?

I am less sure about this one. I am having a hard time with use cases though. I will have to think on it harder.

Another question:

### Should we allow cancellation of a locked stream?

The PR #296 does allow this. It is kind of a violation of the authority principles getReader() is based around. However, without it, you can get in trouble by setting up a pipe chain without having any way to shut it down.

I think the proper solution to this is to change `pipeTo` to return a `{ finished, unpipe() }` object instead of a promise directly. I think this is OK. Most consumer code just changes from `rs.pipeTo(ws).then(...)` into `rs.pipeTo(ws).finished.then(...)`. (We used to have `rs.pipeTo(ws)` return `ws` and say that people should do `rs.pipeTo(ws).closed`.) And now we allow people to `unpipe()`. `unpipe()` is nicer even than `rs.cancel()`, since it gives more control over exactly what happens to `rs` and `ws`. By default it will leave both open, but then you have the option of cancelling `rs` and either `close()`ing or `abort()`ing `ws`.

If we have this in place then we can remove cancellation of locked streams and keep the authority with the reader. We will still have `rs.cancel()` as sugar for (a safer version of) `const reader = rs.getReader(); const result = reader.cancel(); reader.releaseLock(); return result;`.

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/297#issuecomment-78864193

Received on Friday, 13 March 2015 08:24:54 UTC