Skip to content

Commit

Permalink
Tweak pipeTo a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Oct 14, 2021
1 parent 60ba2b2 commit 4fb181c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions reference-implementation/lib/abstract-ops/readable-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,8 @@ function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventC
reader,
{
chunkSteps: chunk => {
currentWrite = transformPromiseWith(
WritableStreamDefaultWriterWrite(writer, chunk), undefined, () => {}
);
currentWrite = WritableStreamDefaultWriterWrite(writer, chunk);
setPromiseIsHandledToTrue(currentWrite);
resolveRead(false);
},
closeSteps: () => resolveRead(true),
Expand Down Expand Up @@ -259,13 +258,18 @@ function ReadableStreamPipeTo(source, dest, preventClose, preventAbort, preventC
setPromiseIsHandledToTrue(pipeLoop());

function waitForWritesToFinish() {
// Another write may have started while we were waiting on this currentWrite, so we have to be sure to wait
// for that too.
const oldCurrentWrite = currentWrite;
return transformPromiseWith(
currentWrite,
() => oldCurrentWrite !== currentWrite ? waitForWritesToFinish() : undefined
);
let oldCurrentWrite;
return promiseResolvedWith(check());

function check() {
// Another write may have started while we were waiting on this currentWrite,
// so we have to be sure to wait for that too.
if (oldCurrentWrite !== currentWrite) {
oldCurrentWrite = currentWrite;
return transformPromiseWith(currentWrite, check, check);
}
return undefined;
}
}

function isOrBecomesErrored(stream, promise, action) {
Expand Down

0 comments on commit 4fb181c

Please sign in to comment.