Re: [whatwg/streams] Reject pending reads when releasing reader (#1168)

I started working on dealing with pending pull-into descriptors after calling `reader.releaseLock()`, following the ideas from https://github.com/whatwg/streams/issues/1103#issuecomment-932763919.

When calling `releaseLock()`, we go through a new controller-specific `[[ReleaseSteps]]` algorithm. For `ReadableStreamDefaultController`, this does nothing. For `ReadableByteStreamController`, this does two things:
* The first pull-into descriptor is marked as "detached" from its read-into request, by setting its `[[readerType]]` to a new special `"none"` value. We cannot discard this descriptor, since the underlying byte source may have already interacted with it through `controller.byobRequest`.
* Any other pull-into descriptors are immediately discarded. (It's impossible for the underlying byte source to have seen these descriptors in its `controller.byobRequest`.)

When the underlying byte source eventually calls `controller.enqueue()` or `byobRequest.respond()`, we finish cleaning up this detached pull-into descriptor. We have to be very careful though:
* The descriptor may have already been partially filled. If so, these bytes need to *first* be copied into the stream's queue. From there, we can try to fill up one or more non-detached pull-into descriptors.

For now, I've only updated the reference implementation. If we're okay with the approach, I can look into updating the spec text.

-- 
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/1168#issuecomment-995313607

Received on Thursday, 16 December 2021 00:07:20 UTC