[whatwg/streams] reader.cancel([ reason ]) "behaves the same as stream.cancel(reason)" is inaccurate and confusing (Issue #1287)

I know it's a non-normative comment, but https://streams.spec.whatwg.org/#default-reader-prototype says:

> await reader.[cancel](https://streams.spec.whatwg.org/#generic-reader-cancel)([ reason ])
If the reader is [active](https://streams.spec.whatwg.org/#active), behaves the same as stream.[cancel](https://streams.spec.whatwg.org/#rs-cancel)(reason).

Because `stream.cancel()` throws if the stream is locked, I incorrectly assumed I would need to
```
reader.releaseLock()
await reader.cancel()
```
However, `reader.cancel()` does throw if the lock has been released; reading the spec, I see that `reader.cancel()`actually doesn't throw if the stream is locked, unlike `stream.cancel()`, so the two don't behave the same at all.

It would be closer to the truth to say `reader.cancel([ reason ])` behaves like `reader.releaseLock()` followed by `stream.cancel(reason)`, since that wouldn't throw;  but, even this is inaccurate, since according to the spec `reader.cancel` doesn't release the lock, it just bypasses the [`IsReadableStreamLocked`](https://streams.spec.whatwg.org/#is-readable-stream-locked) check altogether.



-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1287
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/streams/issues/1287@github.com>

Received on Friday, 7 July 2023 21:13:48 UTC