-
Notifications
You must be signed in to change notification settings - Fork 341
Add Future::join #14
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
Comments
This is somewhat tangential, but I wonder if the behavior of Currently, But consider the fact that the now soft-deprecated macro What if |
Wrote more thoughts here: https://paper.dropbox.com/doc/2019-08-13-Fallible-Futures-Combinators--Aiz0YPhNHzntVEmJj~xUII2fAQ-001Bi7zqOMp6o5cyGuifL -- think this should cover most (and includes e.g. |
is there a reason that let res: (_, _, _) = join!(ok(1), err(2), ok(3)).await;
let res: Vec<_> = join!(vec![ok(1), err(2), ok(3)]).await; Where both would behave exactly the same, polling all features in parallel. |
Macros run before type checking, so this would be hard to to do in a way that allows for: let vec = vec![ok(1), err(2), ok(3)];
join!(v); |
you did not say impossible :) |
It's pretty much impossible. |
I think current behavior of try_join! is near to try_blocks. |
Also, we (futures team) have designed these proc-macros to that they can be easily re-exported, so async-std can easily reuse them. |
We don't want to re-export futures types. |
It is internal implementation of proc-macro, not a type. |
It would be confusing if they use a different syntax than futures's select! macro because async-book also uses it. |
Using it would be an attempt at de-facto stabilizing it, though, as we're committing to our interface. Don't get me wrong, I don't think the futures-rs implementation is bad, just not committed stable |
FWIW, I see it as reasonable to recommend using the |
Coming back to |
This feels alien to me, and I don't know of any precedent in stdlib for this. |
@skade (Mostly) to not confuse which one is the joining thread. |
@vertexclique That's a good point, though, with futures, it's more like A and B get joined to (A,B) by the joiner? |
@skade Truly, in many other library designs, this is a freestanding function. But I prefer having
For iterator based approach instead inheriting About In my opinion, especially |
This is inaccurate. The return signature of
The naming of |
My point is we shouldn't write
You don't know the upcoming futures before the middle of the execution point. There shouldn't be something called
Unfortunately, it is not polling both futures concurrently. We should share a part of the thread pool explicitly for polling purposes to our own task mechanisms' management. If we don't do that writing abstractions will be cumbersome over time. You can take a look at the code of join macro here to understand me better. If you want to write and it is a strict requirement for
Inside the macro trying not to do what
Naming is neither related to execution nor related to syntax. It is based on how other programming languages approach to the topic. And how it will be cleaner. Edit: One more thing that I've found. In higher abstraction than this level (I assume this will be the |
@vertexclique the final point of expressing these concepts less abstract over tasks is indeed very interesting. |
In the 2016 futures announcement post, the
join
combinator was shown as something that would make choosing between several futures easy.In rust-lang/futures-rs#1215 and beyond this was changed to several methods:
join
,join1
,join2
,join3
, andjoin!
,try_join
macros (proc macros since0.3.0-alpha.18
so statements can be written inline).Future::join
It still seems incredibly useful to be able to join multiple futures together, and having a single combinator to do that seems like the simplest API, even if resulting code might not look completely symmetrical. I propose we add
Future::join
:Future::try_join
The
futures-preview
library also exposes atry_join
method. This is useful when you want to unwrap two results. Internally it usesTryFuture
as a reference, which means this method should only exist on futures whereOutput = Result<T, E>
, and I'm not entirely sure if that's feasible. However if it is it might be convenient to also expose:Future::join_all
The third join combinator present is
Future::join_all
. The docs don't make a big sell on them (inefficient, set can't be modified after polling started, preferfutures_unordered
), but it's probably still worth mentioning. I don't think we should add this combinator, but instead point people to usefold
instead:don't do this
do this instead
note: not tested this, but in general I don't think we need to worry about this case too much as handling the unordered case seems much more important and would cover this too.
The text was updated successfully, but these errors were encountered: