Re: [streams] Support reading bytes into buffers allocated by user code on platforms where only async read is available (#253)

What behavior do we want for all the reader methods when the reader is released? I think the following actually is pretty easy to implement:

- `reader.read()` returns `{ value: undefined, done: true }`, or `{ value: view, done: true }` for byte streams
- promises returned by all read() calls before the release get fulfilled with { value: view, done: true }
- `reader.closed` fulfills after release
- `reader.cancel()` is a no-op after release

The implementation strategy is:

- whenever the reader is released, all pending read requests (which must have come from this reader) get fulfilled with `{ value: ..., done: true }`, and then the list of pending read requests gets cleared.
- the reader has its own closedPromise which gets fulfilled "early" if release happens, but otherwise the stream will fulfill/reject the closed promise of any reader it has when appropriate.
- cancel() just has an if statement.

This works no matter whether we store the pending read requests on the reader or on the stream. (My experience so far is that it does not make much difference, precisely because they get cleared whenever a reader is released.)

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/253#issuecomment-77841263

Received on Monday, 9 March 2015 12:02:00 UTC