- From: Mattias Buelens <notifications@github.com>
- Date: Thu, 15 Jul 2021 14:21:50 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/pull/1145@github.com>
Implements #1143.
In my first attempt, I did most of the heavy lifting in a `ReadableStreamBYOBReaderReadFully()` helper that calls `read(view)`. If the first read didn't fill the entire view yet, it immediately calls `read(view)` again but with a special "addToFront" flag so that the new read-into request goes to the *front* of the queue rather than the back. This works fine, but it's not very pretty. It also means we're possibly calling `read(view)` *re-entrantly* from within `ReadIntoRequest.chunkSteps()`, which is somewhat pushing the boundaries of what you can reasonably expect from the spec. 😬 (I've kept this attempt in the commit history, so you can judge for yourselves.)
I then realized that we already have logic that keeps a read-into request in the queue after a `respond()`. When the user performs a BYOB read with a multi-byte typed array, the stream only fulfills the request when at least `elementSize` have been written into the pull-into descriptor. If not, the request stays pending and the pull-into descriptor remains at the head of the queue. Therefore, in my second (and latest) attempt, I add a special type of pull-into descriptor which must stay in the queue as long as `bytesFilled < byteLength`, rather than the usual `bytesFilled < elementSize`. This also works very well, but requires changes across multiple parts of the code.
To do:
* [ ] Write (many more) tests to prove that this actually handles all possible edge cases
* [ ] Write the specification text once we've decided on the approach
---
- [ ] At least two implementers are interested (and none opposed):
* …
* …
- [ ] [Tests](https://github.com/web-platform-tests/wpt) are written and can be reviewed and commented upon at:
* …
- [ ] [Implementation bugs](https://github.com/whatwg/meta/blob/main/MAINTAINERS.md#handling-pull-requests) are filed:
* Chrome: …
* Firefox: …
* Safari: …
(See [WHATWG Working Mode: Changes](https://whatwg.org/working-mode#changes) for more details.)
You can view, comment on, or merge this pull request online at:
https://github.com/whatwg/streams/pull/1145
-- Commit Summary --
* Add ReadableStreamBYOBReader.readFully() (first attempt)
* Revert "Add ReadableStreamBYOBReader.readFully() (first attempt)"
* Add ReadableStreamBYOBReader.readFully()
-- File Changes --
M reference-implementation/lib/ReadableByteStreamController-impl.js (3)
M reference-implementation/lib/ReadableStreamBYOBReader-impl.js (25)
M reference-implementation/lib/ReadableStreamBYOBReader.webidl (1)
M reference-implementation/lib/abstract-ops/readable-streams.js (45)
-- Patch Links --
https://github.com/whatwg/streams/pull/1145.patch
https://github.com/whatwg/streams/pull/1145.diff
--
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/1145
Received on Thursday, 15 July 2021 21:22:03 UTC