According to the spec for TransformStreams at https://streams.spec.whatwg.org/#pipe-chains we are told as follows:
Once a pipe chain is constructed, it will propagate signals regarding how fast chunks should flow through it. If any step in the chain cannot yet accept chunks, it propagates a signal backwards through the pipe chain, until eventually the original source is told to stop producing chunks so fast. This process of normalizing flow from the original source according to how fast the chain can process chunks is called backpressure.
How do we control these signals?
Most specifically, I need after reading, to pause the reader so that I can process the data asynchronously. Once processed, I need to unpause the reader again to receive more data.
What I'm experiencing is a flood of incoming data to the transform method and no obvious way to say "woah, slow down".
Concretely, the original source is given the controller.desiredSize (or byteController.desiredSize) value, and can then adjust its rate of data flow accordingly. This value is derived from the writer.desiredSize corresponding to the ultimate sink, which gets updated as the ultimate sink finishes writing chunks.
The desiredSize property is marked read only on the controller, so this looks like the wrong tool to use. In addition, it seems to be derived from the writer somehow, which isn't the part that we need to stop.
Unfortunately the docs are making no sense to me, they tell me things exist, but not how they mesh together, so I'm lost.
Is there a way to "pause" a reader so the transform method is temporarily suspended, and is there is a way to "unpause" this reader again later once we're ready?
I am using javascript on Firefox v104.