-
Notifications
You must be signed in to change notification settings - Fork 341
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
Replace select!/try_select! with Future::{race,try_race} #405
Conversation
okay yay, got the docs to compile! -- needed to set the params to |
55df8a1
to
49f1c93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like having select
as a function rather than macro.
This reminds me of cmp::min()
/cmp::max()
/Ord::min()
/Ord::max()
. Those functions take two parameters even though sometimes we want to take a minimum/maximum of more than two things. They work fine in practice.
I wonder what you think about having select
and try_select
as methods on FutureExt
versus standalone functions in the future
module. We currently have future::timeout()
function that could've been Future::timeout()
method.
Looking at the methods on Iterator
and functions in the std::iter
module, it seems to me some of the rules are this:
- Iterator constructors go into the
std::iter
module. - Iterator transformers and consumers are methods on the
Iterator
trait.
However, since there are both cmp::min()
and Ord::min()
, it seems there is also a third rule:
- If
a.foo(b)
andb.foo(a)
are equivalent, thenfoo
is handy as both a standalone function and as a trait method.
By that logic, select
should indeed be a trait method, although probably it wouldn't hurt to also have it as a standalone function. But I'm not insisting, just thinking out loud. Not sure what to make of this :)
Leaving down here just a few minor comments, otherwise 👍
I think that's quite reasonable! Especially for |
Implemented all feedback! |
49f1c93
to
d7fbe3f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the feedback! Feel free to merge when CI passes. Looks like Clippy is broken again :(
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
d7fbe3f
to
679da06
Compare
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
fb376ac
to
1dc2057
Compare
Tests are currently broken, filed #431 to fix it. |
This changes the
select
andtry_select
macros into methods onFuture
. Resolves #387. Thanks!Motivation
The output of
join
andtry_join
is polymorphic (n
-sized tuple) which requires a macro.select
andtry_select
don't require polymorphism which makes more sense for it to be a method.Docs issues
Currently the only problem with this patch is that, uhh, the docs no longer build. There's something in the macro that's not working, and I'm not sure what. cc/ @stjepang maybe you have a clue?Future work
I think we should consider adding
join
andtry_join
as methods too, in addition to the existing macros. That way there's polymorphic + non-polymorphic versions of both available, and the APIs become symmetrical again for the non-polymorphic case. Besides, it seems likely that joining 2 futures is the most common case, which can be a nice shorthand.Screenshot