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
async iterators/generators in stream.pipeline() #27140
Comments
cc @mcollina |
So … basically, the desired feature here is that |
@addaleax I guess that'd be pretty great. |
something something migration path from streams to async iterators and generators |
if we can coerce async iterables to streams, that would enable some nice compat with whatwg streams. +1 from me |
How can we coerce to a transform? What signature would you expect from a transform async iterator? |
@mcollina I think any function that takes one argument, which is an async-iterable for Buffers or strings, and returns an async-iterable of that kind should work? More generally, I think we could create an utility class that turns async-iterables of Buffers/strings into a |
https://github.com/mcollina/stream-iterators-utils/blob/master/README.md#utilstoreadablegenerator-opts this is a prototype implementation of that Readable pattern. |
It's awesome that we now have class Transform<I, O> {
static from<I, O>(generatorFn: (input: AsyncIterable<I>) => AsyncIterable<O>): Transform<I, O>
} |
We added support for async generators in pipeline in v13.x. I believe that full-fills this topic. Please re-open of there is anything further to address. |
Apologies for all the code here.
We can consume a
Readable
stream using an async iterator:And we can use async generators similarly to how one would use a
Transform
stream:Then, we can "pipe" these together like so:
That's neat, but also kind of hideous. What if we could leverage
stream.pipeline()
to do something like this?I'm unfamiliar with the guts of
stream.pipeline()
--and completely new to async iterators and generators--so don't know how feasible something like this is.FWIW, the "hideous nested function calls" can be naively replaced by use of the godlike
Array.prototype.reduce()
:Reference: https://twitter.com/b0neskull/status/1115325542566227968
The text was updated successfully, but these errors were encountered: