[whatwg/streams] Add support for asynchronous TransformStreams (Issue #1242)

Right now, it appears that in the case of a TransformStream, all work must be completed on return from the transform() function, meaning that TransformStreams can only be used with synchronous tasks.

In the case of web extensions, chunks are passed via messages to other parts of the browser, and listeners are set up to capture the response. Unfortunately, because the transform() method returns without all the work being complete, there is no backpressure support and data floods in.

As an additional point of breakage, the closing of the ReadableStream causes the premature closing of the WritableStream, which means when the message from the webextension is finally received, the stream to write it to is broken.

What we need is a mechanism to pause and resume the controller that is passed to TransformStream.transform(). As soon as the controller is paused, upstream readers are not triggered, and we can calmly wait until we get a response from the webextension or other async process, unpause the controller, and then continue.

The synchronous tasks only limitation needs to be clearly and loudly documented in the spec, so that ages aren't wasted implementing a system only to find there is no way the system could possibly work.


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

Message ID: <whatwg/streams/issues/1242@github.com>

Received on Sunday, 11 September 2022 19:37:44 UTC