Skip to content
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

StreamExt::flat_map_unordered #2378

Closed
khuey opened this issue Mar 24, 2021 · 1 comment · Fixed by #2083
Closed

StreamExt::flat_map_unordered #2378

khuey opened this issue Mar 24, 2021 · 1 comment · Fixed by #2083
Labels
A-stream Area: futures::stream C-feature-request

Comments

@khuey
Copy link
Contributor

khuey commented Mar 24, 2021

(Inspired by the twitter thread at https://twitter.com/RReverser/status/1374544426622726145)

Flattening a stream of streams into a single stream provides an opportunity for concurrency if you don't care about the output order of the final stream. An efficient solution is difficult to realize with the built-in combinators.

  • StreamExt::flat_map doesn't offer any concurrency
  • stream::select_all requires collecting the stream of streams into an iterable.
  • Using StreamAll directly can be done with StreamExt::collect, but it still requires collecting all streams from the stream of streams first before processing any of the output items.

What is really desired in this case is a combinator that introduces concurrency both within the set of streams yielded by the stream of streams and with the stream of streams itself. Something like (pseudocode)

    let stream_of_streams = ...;
    let accumulated_streams = SelectAll::new();
    loop {
        match select(stream_of_streams.next(), accumulated_streams.next()).await {
           StreamOfStreamsBranch(new_stream) => accumulated_streams.push(new_stream);
           AccumulatedStreamsBranch(item_to_pass_along) => break item_to_pass_along,
        }
    }
@taiki-e
Copy link
Member

taiki-e commented Mar 25, 2021

#1781 #2083

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stream Area: futures::stream C-feature-request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants