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

Add is_finished functionality to JoinSet #5609

Closed
benj2468 opened this issue Apr 7, 2023 · 6 comments
Closed

Add is_finished functionality to JoinSet #5609

benj2468 opened this issue Apr 7, 2023 · 6 comments
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-task Module: tokio/task

Comments

@benj2468
Copy link

benj2468 commented Apr 7, 2023

Is your feature request related to a problem? Please describe.
I would like to pass around a JoinSet to capture a group of Tasks that all belong to a similar larger order "task" I am trying to accomplish. Once an entire group is done, I want to perform some action to inform a user the group is done.

EDIT: I also want to be able to abort the group of tasks (all of them) if some action is taken by a user. This is very important. Say I have the higher-order task A, which has two tasks spawned within it. Aborting task A does not kill the two tasks spawned within. This is how I landed on the need to use a vector or a JoinSet to keep track of all the tasks at the same level.

Describe the solution you'd like
A is_finished or are_finished method on the JoinSet

Something as simple as (I think would work:

  pub fn is_finished(&mut self) {
      self.inner.all(|jh| jh.is_finished());
  }

Describe alternatives you've considered
I've considered making a vector or JoinHandles - which is very simple - but is this not the purpose of a JoinSet?

Additional context
I am happy to PR here -- but wanted to hear from the community if this is even the right approach (I have never contributed to OpenSource before)

@benj2468 benj2468 added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Apr 7, 2023
@Darksonn Darksonn added the M-task Module: tokio/task label Apr 7, 2023
@Darksonn
Copy link
Contributor

Darksonn commented Apr 7, 2023

From your motivation, it sounds like you want to wait for them to finish, rather than just check whether they are currently finished?

@benj2468
Copy link
Author

benj2468 commented Apr 7, 2023

Well, I potentially want to have multiple of these groups running in the the same, and some handler that starts them (that doesn't wait for any one to finish, but can perform an action is any is completed). I guess I could start a single "task" for each "group," then in that "task" wait for the JoinSet to all complete. Would that be the advised approach? I might be convinced that an approach like that is more semantic.

@WhyNotHugo
Copy link

I have a similar need for shotman. In my main loop, I want to check if all tasks of a JoinSet are finished; if they are, my main loop exists, otherwise it continues.

@Darksonn
Copy link
Contributor

Maybe the upcoming #6033 is better for that use-case? Implementing this for JoinSet won't be super efficient.

@WhyNotHugo
Copy link

Indeed, it seems like TaskTracker fits my needs much better. Thanks a lot for the reference!

@Darksonn
Copy link
Contributor

I'm going to close this because it isn't trivial to implement efficiently. I think people should probably use a TaskTracker instead of this function.

@Darksonn Darksonn closed this as not planned Won't fix, can't repro, duplicate, stale Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-task Module: tokio/task
Projects
None yet
Development

No branches or pull requests

3 participants