-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Implement join_all
and try_join_all
on JoinSet
#6664
Comments
|
Regarding this question:
All the methods you proposed consume the But I can see the confusion between the proposed |
Hmm, I think it would make sense to have an opinionated pub fn join_all(self) -> Vec<T> {
let mut output = Vec::new();
while let Some(out) = self.join_next().await {
match out {
Ok(res) => output.push(res),
Err(err) if err.is_panic() => panic::resume_unwind(err.into_panic()),
Err(err) => panic!("{err}"),
}
}
output
} Since this takes |
@Darksonn So you would suggest that instead of returning some sort of Maybe it would be better to return something like |
@tglane The purpose of the new API is to create a shortcut for a common case. For maximum flexibility, a user can manually join each task with |
Yeah, I think it makes sense. People who want more complex stuff can write their own loop. |
Ok, I mean you're right, one can write their own loop if needed. So it's probably fine to just panic if well documented. |
Is your feature request related to a problem? Please describe.
The
futures
crate currently provides two very convenient functions for awaiting an Iterator of futures withjoin_all
andtry_join_all
. However, these functions are currently missing inJoinSet
, requiring us to loop over the set manually.Describe the solution you'd like
I would like to see the addition of the aforementioned methods to
JoinSet
, as it would make its usage more ergonomic.Additional context
I am not quite sure what the best method definition is, since every task spawned by set the set could potentially fail with a
JoinError
. Here are some ideas I came up with:join_all
Conservative
This is the least opinionated approach, but also not that useful in my opinion. Granted, users could iterate again over the
Vec
, but then I am not really convinced by its utility over just constructing the initialwhile
loop.Filtered out
JoinError
sWe could also just include all
Ok
variants, but this could be confusing because erroneous tasks are just silently ignored.Opinionated
join_all
Just short-circuit as soon as one task failed. This is a lot more useful, but it could be quite confusing for the user, since it could also be understood as
try_join_all
try_join_all
I would also like to have a
try_join_all
that reacts on some user providedResult
, whereTryJoinAllError
Could be eitherK
orJoinError
.In addition, I am not quite sure how do handle the remaining tasks in case of a panic or
Error
. Should we explicitly abort them, or just let them run? I would like to hear your thoughts on this.The text was updated successfully, but these errors were encountered: