From 70dee35733e1cd60b52ac34ce17f34e4df815a8a Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Fri, 4 Jun 2021 23:37:41 +0200 Subject: [PATCH] Respond before enqueue in ReadableByteStreamTee --- index.bs | 7 +++++-- .../lib/abstract-ops/readable-streams.js | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/index.bs b/index.bs index 53fe8e8ad..bee5a6504 100644 --- a/index.bs +++ b/index.bs @@ -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|).

The microtask delay here is necessary because it takes at least a microtask to diff --git a/reference-implementation/lib/abstract-ops/readable-streams.js b/reference-implementation/lib/abstract-ops/readable-streams.js index b622aa552..f19e53c37 100644 --- a/reference-implementation/lib/abstract-ops/readable-streams.js +++ b/reference-implementation/lib/abstract-ops/readable-streams.js @@ -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); } });