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

Add backpressure information to tee, clone #16804

Merged
merged 4 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
respond to pr feedback. Use _x_ instead of *x* for emphasis
  • Loading branch information
yonran committed Jun 16, 2022
commit c5bc0863c8781f85aba80e142bb4ce7483b3c255
8 changes: 4 additions & 4 deletions files/en-us/web/api/readablestream/tee/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ a response from the server and stream it to the browser, but also stream it to t
ServiceWorker cache. Since a response body cannot be consumed more than once, you'd need
two copies to do this.

A teed stream will partially signal backpressure at the rate of the *faster* consumer
A teed stream will partially signal backpressure at the rate of the _faster_ consumer
of the two `ReadableStream` branches,
and unread data is enqueued internally on the slower consumed `ReadableStream`
without any limit or backpressure.
That is, when *both* branches have an unread element in their internal queue,
then the original `ReadableStream`’s controller’s queue will start to fill up,
That is, when _both_ branches have an unread element in their internal queue,
then the original `ReadableStream`’s controller’s internal queue will start to fill up,
and once its {{domxref("ReadableStreamDefaultController.desiredSize", "desiredSize")}} ≤ 0
or byte stream controller {{domxref("ReadableByteStreamController.desiredSize", "desiredSize")}} ≤ 0,
then the controller will stop calling `pull(controller)` on the
Expand All @@ -38,7 +38,7 @@ If only one branch is consumed, then the entire body will be enqueued in memory.
Therefore, you should not use the built-in `tee()` to read very large streams
in parallel at different speeds.
Instead, search for an implementation that fully backpressures
to the speed of the *slower* consumed branch.
to the speed of the _slower_ consumed branch.

To cancel the stream you then need to cancel both resulting branches. Teeing a stream
will generally lock it for the duration, preventing other readers from locking it.
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/request/clone/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The **`clone()`** method of the {{domxref("Request")}} interface creates a copy

Like the underlying {{domxref("ReadableStream.tee")}} api,
the {{domxref("Request.body", "body")}} of a cloned `Response`
will signal backpressure at the rate of the *faster* consumer of the two bodies,
will signal backpressure at the rate of the _faster_ consumer of the two bodies,
and unread data is enqueued internally on the slower consumed `body`
without any limit or backpressure.
Beware when you construct a `Request` from a stream and then `clone` it.
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/response/clone/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The **`clone()`** method of the {{domxref("Response")}} interface creates a clon

Like the underlying {{domxref("ReadableStream.tee")}} api,
the {{domxref("Response.body", "body")}} of a cloned `Response`
will signal backpressure at the rate of the *faster* consumer of the two bodies,
will signal backpressure at the rate of the _faster_ consumer of the two bodies,
and unread data is enqueued internally on the slower consumed `body`
without any limit or backpressure.
Backpressure refers to the mechanism by which the streaming consumer of data
Expand Down