Re: [streams] Byte stream update, including reference implementation (#361)

> +
> +  reader._closedPromise_resolve(undefined);
> +  reader._closedPromise_resolve = undefined;
> +  reader._closedPromise_reject = undefined;
> +
> +  if (IsReadableByteStreamReader(reader)) {
> +    for (const req of reader._readRequests) {
> +      req.resolve(CreateIterResultObject(undefined, true));
> +    }
> +
> +    reader._readRequests = [];
> +  } else {
> +    assert(IsReadableByteStreamByobReader(reader), 'reader must be ReadableByteStreamByobReader');
> +
> +    if (reader._readIntoRequests.length > 0) {
> +      return;

Yeah, this is complicated.

We have 3 options:

1. Wait for the buffer to return. Once returned, `controller.respond(0, returnedBuffer)` and `controller.close()`
1. `controller.close()` and wait for the buffer to return. Once returned `controller.respond(0, returnedBuffer)`
1. Accept the same sequence (at controller side) as (2) but make the reader look not closed until the `respond()` is made

I chose (2) to thinking of a case like this:

At the time when an underlying byte source notices that no more data comes (or on `reader.cancel()` call), the buffer passed via `pullInto()` may still owned by some other thread and we need to wait for the buffer to be returned. (*)

(2) allows faster delivery of closure signal to the consumer.

(1) and (3) are equivalent from the view point of the consumer. So, I'd just choose (1) from them.

I'm not sure (*) is so realistic. But it seems `reader.cancel()` should be able to mark the stream closed synchronously. This requires the same state transition sequence as (2).

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/361/files#r33675147

Received on Wednesday, 1 July 2015 12:59:11 UTC