Re: [whatwg/streams] Support teeing readable byte streams (#1114)

@MattiasBuelens commented on this pull request.



> @@ -2055,6 +2044,29 @@ The following abstract operations operate on {{ReadableStream}} instances at a h
  |startAlgorithm| throws.
 </div>
 
+<div algorithm>
+ <dfn abstract-op lt="CreateReadableByteStream"
+ id="create-readable-byte-stream">CreateReadableByteStream(|startAlgorithm|, |pullAlgorithm|,
+ |cancelAlgorithm|[, |highWaterMark|, [, |autoAllocateChunkSize|]])</dfn> performs the following

Sure, I can remove them for now. That said, we might need to bring them back if/when we introduce "transform byte streams".

> +  1. [=Upon rejection=] of |thisReader|.[=ReadableStreamGenericReader/[[closedPromise]]=] with reason
+     |r|,
+   1. If |reader| is not |thisReader|, return.
+   1. Perform ! [$ReadableByteStreamControllerError$](|branch1|.[=ReadableStream/[[controller]]=],
+      |r|).
+   1. Perform ! [$ReadableByteStreamControllerError$](|branch2|.[=ReadableStream/[[controller]]=],
+      |r|).
+   1. If |canceled1| is false or |canceled2| is false, [=resolve=] |cancelPromise| with undefined.
+ 1. Let |pullWithDefaultReader| be the following steps:
+  1. If |reader| [=implements=] {{ReadableStreamBYOBReader}},
+   1. Assert: |reader|.[=ReadableStreamBYOBReader/[[readIntoRequests]]=] is [=list/is empty|empty=].
+   1. Perform ! [$ReadableStreamReaderGenericRelease$](|reader|).
+   1. Set |reader| to ! [$AcquireReadableStreamDefaultReader$](|stream|).
+   1. Perform |forwardReaderError|, given |reader|.
+  1. Let |readRequest| be a [=read request=] with the following [=struct/items=]:
+   : [=read request/chunk steps=], given |chunk|

Seems like _chunk_ is more common. Currently [on `main`](https://github.com/whatwg/streams/blob/9beefc2ac041a1a848088962d56eb03e89a8bf07/index.bs):
* `[=read request/chunk steps=], given |chunk|`: 5 matches
* `[=read request/chunk steps=], given |value|`: 1 match
* `[=read request/chunk steps=], given |view|`: 1 match
* `[=read-into request/chunk steps=], given |chunk|`: 2 matches
* `[=read-into request/chunk steps=], given |filledView|`: 1 match

I think I'll change `ReadableStreamTee` to use _chunk_ instead of _value_. 🙂

> +   1. Set |reader| to ! [$AcquireReadableStreamBYOBReader$](|stream|).
+   1. Perform |forwardReaderError|, given |reader|.
+  1. Let |byobBranch| be |branch2| if |forBranch2| is true, and |branch1| otherwise.
+  1. Let |otherBranch| be |branch2| if |forBranch2| is false, and |branch1| otherwise.
+  1. Let |readIntoRequest| be a [=read-into request=] with the following [=struct/items=]:
+   : [=read-into request/chunk steps=], given |chunk|
+   ::
+    1. [=Queue a microtask=] to perform the following steps:
+     1. Set |reading| to false.
+     1. Let |byobCanceled| be |canceled2| if |forBranch2| is true, and |canceled1| otherwise.
+     1. Let |otherCanceled| be |canceled2| if |forBranch2| is false, and |canceled1| otherwise.
+     1. If |otherCanceled| is false,
+      1. Let |clonedChunk| be ? [$CloneAsUint8Array$](|chunk|).
+      1. Perform ! [$ReadableByteStreamControllerEnqueue$](|otherBranch|.[=ReadableStream/[[controller]]=],
+         |clonedChunk|).
+     1. If |byobCanceled| is false,

We still need to clone the chunk first, since `ReadableByteStreamControllerRespondWithNewView` will transfer it. So we'd need do:

> 1. If _otherCanceled_ is false, set _clonedChunk_ to CloneAsUint8Array(_chunk_)
> 1. If _byobCanceled_ is false, perform ReadableByteStreamControllerRespondWithNewView(..., _chunk_)
> 1. If _otherCanceled_ is false, perform ReadableByteStreamControllerEnqueue(..., _clonedChunk_)

Might be a bit weird? Or we'd have repeat the `ReadableByteStreamControllerRespondWithNewView` step:

> 1. If _otherCanceled_ is false,
>    1. Let _clonedChunk_ be CloneAsUint8Array(_chunk_)
>    1. If _byobCanceled_ is false, perform ReadableByteStreamControllerRespondWithNewView(..., _chunk_)
>    1. Perform ReadableByteStreamControllerEnqueue(..., _clonedChunk_)
> 1. Otherwise, if _byobCanceled_ is false, perform ReadableByteStreamControllerRespondWithNewView(..., _chunk_)

-- 
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/1114#discussion_r645851406

Received on Friday, 4 June 2021 21:34:30 UTC