Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f6cdfbf

Browse filesBrowse files
MattiasBuelensaduh95
authored andcommitted
stream: optimize webstreams pipeTo
PR-URL: #62079 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 7f989f0 commit f6cdfbf
Copy full SHA for f6cdfbf

1 file changed

+12-14Lines changed: 12 additions & 14 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/webstreams/readablestream.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/readablestream.js
+12-14Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,10 +1532,12 @@ function readableStreamPipeTo(
15321532
}
15331533

15341534
async function step() {
1535-
if (shuttingDown)
1536-
return true;
1535+
if (shuttingDown) return true;
15371536

1538-
await writer[kState].ready.promise;
1537+
if (dest[kState].backpressure) {
1538+
await writer[kState].ready.promise;
1539+
if (shuttingDown) return true;
1540+
}
15391541

15401542
const controller = source[kState].controller;
15411543

@@ -1549,7 +1551,6 @@ function readableStreamPipeTo(
15491551
while (controller[kState].queue.length > 0) {
15501552
if (shuttingDown) return true;
15511553

1552-
source[kState].disturbed = true;
15531554
const chunk = dequeueValue(controller);
15541555

15551556
if (controller[kState].closeRequested && !controller[kState].queue.length) {
@@ -1563,20 +1564,17 @@ function readableStreamPipeTo(
15631564
setPromiseHandled(state.currentWrite);
15641565

15651566
// Check backpressure after each write
1566-
if (dest[kState].state === 'writable') {
1567-
const desiredSize = writer.desiredSize;
1568-
if (desiredSize !== null && desiredSize <= 0) {
1569-
// Backpressure - stop batch and wait for ready
1570-
break;
1571-
}
1567+
if (dest[kState].backpressure) {
1568+
// Backpressure - stop batch and wait for ready
1569+
break;
1570+
} else if (dest[kState].state !== 'writable' || writableStreamCloseQueuedOrInFlight(dest)) {
1571+
// Closing or erroring - stop batch and wait for shutdown
1572+
break;
15721573
}
15731574
}
15741575

15751576
// Trigger pull if needed after batch
1576-
if (source[kState].state === 'readable' &&
1577-
!controller[kState].closeRequested) {
1578-
readableStreamDefaultControllerCallPullIfNeeded(controller);
1579-
}
1577+
readableStreamDefaultControllerCallPullIfNeeded(controller);
15801578

15811579
// Check if stream closed during batch
15821580
if (source[kState].state === 'closed') {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.