Re: [whatwg/streams] The difference between ReadableStream.cancel() and ReadableStreamDefaultReader.cancel()? (#1033)

> Does it mean, that the better/proper/primary/shorter cancellation route is:
> 
> ```js
> reader.releaseLock();
> stream.cancel();
> ```

It's more a question of whether you already have a reader locked to your stream or not.
* If you have a reader, you must use `reader.cancel()`, because `stream.cancel()` only works when your stream is unlocked.
* If you have a reader, but you don't need it anymore after cancelling, you can do either `reader.cancel(); reader.releaseLock()` or `reader.releaseLock(); stream.cancel()`. Both are equivalent, and take up pretty much the same amount of code.
* If you don't have a reader, you could cancel ["the long way"](https://github.com/whatwg/streams/issues/1033#issuecomment-600933751), or you can use `stream.cancel()` to get the same result.

> Also, does the "loss of interest" signaling means that i shall not do:
> 
> ```js
> reader = stream.getReader();
> ```
> 
> ..anymore, and i should recreate a stream?

Yes. Canceling a stream is a "terminal" action: the stream can never become readable again. You will no longer be able to read chunks from it, even if you acquire a new reader.

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

Received on Friday, 20 March 2020 00:06:48 UTC