Re: [streams] What types does ReadableByteStream's reader's read(x) accept and return? (#295)

Reference implementation in https://github.com/whatwg/streams/tree/bytestream is now ready for review.

Current implementation is kinda combination of (2) and (3) of domenic's idea.

----

When getByobReader() and read(view) is called, underlyingByteSource.pullInto() is called.

When getReader() and read() is called, underlyingByteSource.pull() is called.

As far as the stream is readable and controller.close() has not yet been called, the underlyingByteSource can call controller.enqueue().

If there's pending pullInto call, the underlyingByteSource can call controller.respond().

----

If byobReader.read(new Float64Array(2)) is called when:
- 1 byte queued -> fill the first byte, and repeat pullInto() with the not-yet-filled region
- 8 byte queued -> fulfill with 1-element filled
- 9 byte queued -> fulfill with 1-element filled, and then keep the remaining 1 byte queued
- 16 byte queued -> fulfill whole view
- 17 byte queued -> fulfill and keep the remaining 1 byte queued

When there is a pending read request of new Float64Array(2) with 0 byte filled:
- if controller.respond(1) is called -> fill the first byte and repeat calling pullInto
- if controller.respond(8) is called -> fulfill with 1-element
- if controller.close() is called -> close the stream. as the buffer is currently owned by the underlying byte source, wait for respond() call. when respond() call happens, fulfill the pending request with the returned buffer and done of true.

When there is a pending read request of new Float64Array(2) with 1 byte filled:
- if controller.respond(1) is called -> fill the second byte and repeat calling pullInto
- if controller.respond(7) is called -> fulfill with 1-element
- if controller.close() is called -> error the stream and throw

----

When to call pull or pullInto again:
- if we're inside pull or pullInto, instruct the pull caller or pullInto caller to repeat pull or pullInto if needed
- otherwise:
    - if it's a result of invocation of a method on the controller, queue a microtask to run pull or pullInto later if needed
    - otherwise, i.e. it's a result of read(), read(view) on a reader, run pull or pullInto immediately and repeat if needed.


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

Received on Thursday, 11 June 2015 08:46:28 UTC