Re: [whatwg/streams] Various fixes for readable byte streams (#1123)

> With this, the second case (passing view.subarray(0, 0)) would be accepted when the stream is closed. Ownership of the buffer is returned, and the read-into request can be fulfilled.

Right, OK, this is coming back to me now. So I guess the question is whether we want to support this use case. In particular, it seems like an underlying source that closes a stream without first returning the pending BYOB request is doing the wrong thing. Allowing it to do the wrong thing but then return the buffer by doing `view.subarray(0, 0)` doesn't seem that useful?

From the other direction, if a stream consumer wants to cancel the stream (thus closing it), do they really expect to get their buffer back? It seems like annoying boilerplate to require that underlying source authors intercept cancels and send back the buffer. I'm inclined to just say that if you cancel the stream, you won't get your buffer back.

> As for the second change: [...] This is to fulfill the contract of read(view). From the domintro:

So my main question is whether the contract, as explained in the domintro, is meant to be 100% accurate, or is instead meant to cover the happy path.

I wish we had better historical notes on what the purpose of respondWithNewView() was. (The only reference I can find is https://github.com/whatwg/streams/issues/495#issuecomment-256945073 which suports your interpretation.) But it seems possible that one envisioned use case was when it's wasteful for the stream to write into the same backing memory region, for whatever reason. For example, the stream was handed some data from a non-BYOB API, or had some queued up because backpressure hadn't fully propagated, or whatever. In that case, respondWithNewView() can be used to say "I know you handed me a buffer, but instead of copying into that and wasting everyone's time, let me just give you a new one".

Probably this is not accurate. E.g. the spec's existing check on view length implies that such freedom was not intended. So I am comfortable with this change. I just thought I'd throw out the above paragraph in case you had thoughts :).

-- 
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/pull/1123#issuecomment-841413902

Received on Friday, 14 May 2021 18:08:45 UTC