GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: fold desired-size check into WHATWG backpressure update · nodejs/node@de4ca2c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/webstreams
    • writablestream.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/webstreams/writablestream.js‎

Copy file name to clipboardExpand all lines: lib/internal/webstreams/writablestream.js
+12-21Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -757,13 +757,15 @@ function writableStreamClose(stream) {
757757
return promise;
758758
}
759759

760-
function writableStreamUpdateBackpressure(stream, backpressure) {
761-
const streamState = stream[kState];
762-
assert(streamState.state === 'writable');
763-
assert(!streamState.closeQueuedOrInFlight);
764-
const {
765-
writer,
766-
} = streamState;
760+
// Callers invoke this only in the 'writable' state with no close queued or
761+
// in flight (the two conditions the spec's assertions check), so the
762+
// backpressure value is derived here from the desired size instead of being
763+
// computed and passed in by each caller.
764+
function writableStreamUpdateBackpressure(controller, streamState) {
765+
const controllerState = controller[kState];
766+
const backpressure =
767+
controllerState.highWaterMark - controllerState.queueTotalSize <= 0;
768+
const writer = streamState.writer;
767769
if (writer !== undefined && streamState.backpressure !== backpressure) {
768770
if (backpressure) {
769771
// The spec replaces [[readyPromise]] with a fresh pending promise;
@@ -1100,9 +1102,7 @@ function writableStreamDefaultControllerWrite(controller, chunk, chunkSize) {
11001102
const streamState = stream[kState];
11011103
if (!streamState.closeQueuedOrInFlight &&
11021104
streamState.state === 'writable') {
1103-
writableStreamUpdateBackpressure(
1104-
stream,
1105-
writableStreamDefaultControllerGetBackpressure(controller));
1105+
writableStreamUpdateBackpressure(controller, streamState);
11061106
}
11071107
writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
11081108
}
@@ -1128,9 +1128,7 @@ function writableStreamDefaultControllerProcessWrite(controller, chunk) {
11281128
dequeueValue(controller);
11291129
if (!streamState.closeQueuedOrInFlight &&
11301130
state === 'writable') {
1131-
writableStreamUpdateBackpressure(
1132-
stream,
1133-
writableStreamDefaultControllerGetBackpressure(controller));
1131+
writableStreamUpdateBackpressure(controller, streamState);
11341132
}
11351133
writableStreamDefaultControllerAdvanceQueueIfNeeded(controller);
11361134
};
@@ -1229,10 +1227,6 @@ function writableStreamDefaultControllerClearAlgorithms(controller) {
12291227
controller[kState].sizeAlgorithm = undefined;
12301228
}
12311229

1232-
function writableStreamDefaultControllerGetBackpressure(controller) {
1233-
return writableStreamDefaultControllerGetDesiredSize(controller) <= 0;
1234-
}
1235-
12361230
function writableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {
12371231
const {
12381232
queue,
@@ -1317,9 +1311,7 @@ function setupWritableStreamDefaultController(
13171311
};
13181312
stream[kState].controller = controller;
13191313

1320-
writableStreamUpdateBackpressure(
1321-
stream,
1322-
writableStreamDefaultControllerGetBackpressure(controller));
1314+
writableStreamUpdateBackpressure(controller, stream[kState]);
13231315

13241316
const startResult = startAlgorithm();
13251317

@@ -1402,7 +1394,6 @@ module.exports = {
14021394
writableStreamDefaultControllerError,
14031395
writableStreamDefaultControllerClose,
14041396
writableStreamDefaultControllerClearAlgorithms,
1405-
writableStreamDefaultControllerGetBackpressure,
14061397
writableStreamDefaultControllerAdvanceQueueIfNeeded,
14071398
setupWritableStreamDefaultControllerFromSink,
14081399
setupWritableStreamDefaultController,

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.