Re: [whatwg/streams] make TransformStream respect backpressure (#550)

tyoshino commented on this pull request.



> @@ -262,12 +238,32 @@ class TransformStreamSource {
 
     transformStream._readableController = c;
 
-    return this._startPromise;
+    // delay the first source.pull call until there is backpressure
+    return this._startPromise.then(() => {

I just suggested refactoring without any behavior change. You can pass a promise already then-ed with this callback in TransformStream's constructor to the constructor of TransformStreamSource. And here you just return the passed promise stored in _startPromise. Then, we can encapsulate the operations on the variable of TransformStream inside the constructor.

>      assert(this._writableController !== undefined);
     assert(this._readableController !== undefined);
 
+    const desiredSize = this._readableController.desiredSize;
+    TransformStreamSetBackpressure(this, desiredSize <= 0);

Once the TransformStream constructor completes, user can start read()-ing from the readable side. If the strategy is set to HWM=0, i.e. configured to only pull() only when there's one or more read()s, pull() invocation is the only signal to remove backpressure. So, if you start with calling TransformStreamSetBackpressure(this, true), and TransformStreamSource() starts with being blocked on _backpressureChangePromise's fulfillment, I thought that there's no one who can fulfill it as pull() is suppressed.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/550

Received on Thursday, 27 October 2016 00:16:21 UTC