-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TransformStream byte streams #616
Comments
Strawman proposal: Can we split the TransformStream controller into a readable controller and a writable controller? The readable controller would be the one that is passed into transform() methods, since it provides enqueue(). Either controller could call methods on the transformer object. Does this even make sense? |
I think it's worth trying though it might result in making the interface almost the same as direct use of a raw ReadableStream and WritableStream which may look useless. I think this wouldn't block ship of |
My idea is that the interface to transformer-authors or transform-consumers doesn't change: only the internal implementation. So for default->default transform streams it would look exactly the same as it does today. For default->byte streams the controller interface visible to the transformer would have a byobRequest accessor. For byte->default streams the controller would have the same API as today, but the transformer might have additional methods depending on whether we choose RBYOB, KYOB or something else. The difference is that if, for example, we added a "char" type in future, would we need to add 5 new controller types to TransformStream, or only 2? |
That sounds attractive, but would it in practice save code? It seems like the "glue" code that comprises the majority of the transform stream implementation kind of needs to know about the various controller types in order to perform WS -> transformation -> RS transfer. We could help things by making more abstract operations into polymorphic methods (like [[Cancel]] and [[Pull]] currently are) but it seems like there would need to be some transform stream code that actually uses the BYOB request and such, right? And that code needs to account for the permutations involved. |
I thought about it a bit more, and decided that talking about multiple controllers on a single object was just confusing. Instead, what I think we should do is rename TransformStreamSource to TransformStreamDefaultSource, and similarly with TransformStreamSink. Then for readable byte streams we add have TransformStreamByteSource. The controller is a thin wrapper around the ReadableStream's controller. I have a rough idea how the Source and Sink should communicate. The Sink calls a polymorphic method on the Source with a promise while will fulfill when the transform completes. That method returns a promise chained from the passed in promise which will fulfill when the Source is ready for more data. This all falls apart if the name or arguments of the transform() method need to depend on the type of the ReadableStream. |
@isonmad submitted a pull request #601 to support asymmetric default->byte TransformStream objects. Although only default->default and default->byte transforms are possible at the moment, I expect that byte->default and byte->byte will become useful in the future.
@tyoshino made this comment on #601:
I think it would be good to split off discussion into this issue.
The text was updated successfully, but these errors were encountered: