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

future::select example #2163

Closed
keepsimple1 opened this issue May 20, 2020 · 2 comments
Closed

future::select example #2163

keepsimple1 opened this issue May 20, 2020 · 2 comments
Labels

Comments

@keepsimple1
Copy link
Contributor

I felt the current example in future::select documentation is too advanced / complicated for a new user. I think that whoever trying to read this example is likely a new user.

/// use futures::future::{self, Either, Future, FutureExt};
///
/// // A poor-man's join implemented on top of select
///
/// fn join<A, B>(a: A, b: B) -> impl Future<Output=(A::Output, B::Output)>
/// where A: Future + Unpin,
/// B: Future + Unpin,
/// {
/// future::select(a, b).then(|either| {
/// match either {
/// Either::Left((x, b)) => b.map(move |y| (x, y)).left_future(),
/// Either::Right((y, a)) => a.map(move |x| (x, y)).right_future(),
/// }
/// })
/// }

Is it possible to have a simpler / more basic example for this function? Particularly, it will be great if the example can clearly show what the value(s) returned in each arm are.

@ghost
Copy link

ghost commented Jun 17, 2020

I'd also love an example that is:

  1. more explicit about what the elements of the pairs within the Either are, you have to do a lot of parsing of this example to tell what x, a, y, and b are meant to mean

  2. uses this function in a more realistic scenario than reimplementing something select doesn't do

@taiki-e
Copy link
Member

taiki-e commented Sep 21, 2020

Done in #2182

@taiki-e taiki-e closed this as completed Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants