Skip to content

Commit 2db6b94

Browse files
Add WritableStreamDefaultController.releaseBackpressure()
1 parent 5885d94 commit 2db6b94

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

reference-implementation/lib/WritableStreamDefaultController-impl.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ exports.implementation = class WritableStreamDefaultControllerImpl {
2121
aos.WritableStreamDefaultControllerError(this, e);
2222
}
2323

24+
releaseBackpressure() {
25+
const state = this._stream._state;
26+
if (state !== 'writable') {
27+
return;
28+
}
29+
aos.WritableStreamDefaultControllerReleaseBackpressure(this);
30+
}
31+
2432
[AbortSteps](reason) {
2533
const result = this._abortAlgorithm(reason);
2634
aos.WritableStreamDefaultControllerClearAlgorithms(this);

reference-implementation/lib/WritableStreamDefaultController.webidl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
interface WritableStreamDefaultController {
33
readonly attribute AbortSignal signal;
44
void error(optional any e);
5+
void releaseBackpressure();
56
};

reference-implementation/lib/abstract-ops/writable-streams.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Object.assign(exports, {
2727
WritableStreamDefaultControllerClearAlgorithms,
2828
WritableStreamDefaultControllerError,
2929
WritableStreamDefaultControllerErrorIfNeeded,
30+
WritableStreamDefaultControllerReleaseBackpressure,
3031
WritableStreamDefaultWriterAbort,
3132
WritableStreamDefaultWriterClose,
3233
WritableStreamDefaultWriterCloseWithErrorPropagation,
@@ -543,6 +544,7 @@ function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm
543544

544545
controller._abortController = new AbortController();
545546
controller._started = false;
547+
controller._releaseBackpressure = false;
546548

547549
controller._strategySizeAlgorithm = sizeAlgorithm;
548550
controller._strategyHWM = highWaterMark;
@@ -657,6 +659,9 @@ function WritableStreamDefaultControllerErrorIfNeeded(controller, error) {
657659
}
658660

659661
function WritableStreamDefaultControllerGetBackpressure(controller) {
662+
if (controller._releaseBackpressure === true) {
663+
return false;
664+
}
660665
const desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller);
661666
return desiredSize <= 0;
662667
}
@@ -727,6 +732,19 @@ function WritableStreamDefaultControllerProcessWrite(controller, chunk) {
727732
);
728733
}
729734

735+
function WritableStreamDefaultControllerReleaseBackpressure(controller) {
736+
const stream = controller._stream;
737+
assert(stream._state === 'writable');
738+
739+
controller._releaseBackpressure = true;
740+
741+
if (WritableStreamHasOperationMarkedInFlight(stream) === false &&
742+
WritableStreamCloseQueuedOrInFlight(stream) === false) {
743+
const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
744+
WritableStreamUpdateBackpressure(stream, backpressure);
745+
}
746+
}
747+
730748
function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) {
731749
try {
732750
EnqueueValueWithSize(controller, chunk, chunkSize);
@@ -735,6 +753,8 @@ function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) {
735753
return;
736754
}
737755

756+
controller._releaseBackpressure = false;
757+
738758
const stream = controller._stream;
739759
if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._state === 'writable') {
740760
const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);

0 commit comments

Comments
 (0)