Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require pipeTo() to properly use the destination queue #720

Merged
merged 5 commits into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,11 @@ ReadableStream(<var>underlyingSource</var> = {}, { <var>size</var>, <var>highWat
from _reader_.
* If _reader_ is a <a>BYOB reader</a>, WritableStreamDefaultWriterGetDesiredSize(_writer_) should be used to
determine the size of the chunks read from _reader_.
* Otherwise, WritableStreamDefaultWriterGetDesiredSize(_writer_) may be used to determine the flow rate
heuristically, e.g. by delaying reads while it is judged to be "low" compared to the size of chunks that have
been typically read.
* Reads or writes should not be delayed for reasons other than these backpressure signals.
<p class="example" id="example-bad-backpressure">An implementation that waits for each write to successfully
complete before proceeding to the next read/write operation violates this recommendation. In doing so, such an
implementation makes the <a>internal queue</a> of _dest_ useless, as it ensures _dest_ always contains at most
one queued <a>chunk</a>.</p>
* <strong>Shutdown must stop all activity:</strong> if _shuttingDown_ becomes *true*, the user agent must not
initiate further reads from _reader_ or writes to _writer_. (Ongoing reads and writes may finish.) In particular,
the user agent must check the below conditions on *this*.[[state]] and _dest_.[[state]] before performing any
Expand Down
13 changes: 4 additions & 9 deletions reference-implementation/lib/readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ class ReadableStream {
return writer._readyPromise.then(() => {
return ReadableStreamDefaultReaderRead(reader).then(({ value, done }) => {
if (done === true) {
return undefined;
return;
}

currentWrite = WritableStreamDefaultWriterWrite(writer, value);
return currentWrite;
currentWrite = WritableStreamDefaultWriterWrite(writer, value).catch(() => {});
});
})
.then(pipeLoop);
Expand Down Expand Up @@ -202,17 +201,13 @@ class ReadableStream {
}
}

function waitForCurrentWrite() {
return currentWrite.catch(() => {});
}

function shutdownWithAction(action, originalIsError, originalError) {
if (shuttingDown === true) {
return;
}
shuttingDown = true;

waitForCurrentWrite().then(() => {
currentWrite.then(() => {
return action().then(
() => finalize(originalIsError, originalError),
newError => finalize(true, newError)
Expand All @@ -227,7 +222,7 @@ class ReadableStream {
}
shuttingDown = true;

waitForCurrentWrite().then(() => {
currentWrite.then(() => {
finalize(isError, error);
})
.catch(rethrowAssertionErrorRejection);
Expand Down
2 changes: 1 addition & 1 deletion reference-implementation/web-platform-tests