Skip to content

Commit

Permalink
Respond before enqueue in ReadableByteStreamTee
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Jun 13, 2021
1 parent 53ada54 commit 296c901
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2399,10 +2399,13 @@ create them does not matter.
1. Let |otherCanceled| be |canceled2| if |forBranch2| is false, and |canceled1| otherwise.
1. If |otherCanceled| is false,
1. Let |clonedChunk| be ? [$CloneAsUint8Array$](|chunk|).
1. If |byobCanceled| is false, perform !
[$ReadableByteStreamControllerRespondWithNewView$](|byobBranch|.[=ReadableStream/[[controller]]=],
|chunk|).
1. Perform ! [$ReadableByteStreamControllerEnqueue$](|otherBranch|.[=ReadableStream/[[controller]]=],
|clonedChunk|).
1. If |byobCanceled| is false,
1. Perform ! [$ReadableByteStreamControllerRespondWithNewView$](|byobBranch|.[=ReadableStream/[[controller]]=],
1. Otherwise, if |byobCanceled| is false, perform !
[$ReadableByteStreamControllerRespondWithNewView$](|byobBranch|.[=ReadableStream/[[controller]]=],
|chunk|).

<p class="note">The microtask delay here is necessary because it takes at least a microtask to
Expand Down
6 changes: 4 additions & 2 deletions reference-implementation/lib/abstract-ops/readable-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,11 @@ function ReadableByteStreamTee(stream) {

if (otherCanceled === false) {
const clonedChunk = CloneAsUint8Array(chunk);
if (byobCanceled === false) {
ReadableByteStreamControllerRespondWithNewView(byobBranch._controller, chunk);
}
ReadableByteStreamControllerEnqueue(otherBranch._controller, clonedChunk);
}
if (byobCanceled === false) {
} else if (byobCanceled === false) {
ReadableByteStreamControllerRespondWithNewView(byobBranch._controller, chunk);
}
});
Expand Down

0 comments on commit 296c901

Please sign in to comment.