[async] Wait for all instances to be dropped

I'm spawning a bunch of tasks that can be killed using an application-defined task identifier. On shutdown, I want to signal every task to self-terminate and then allow the caller to wait until all the tasks have terminated. Earlier I didn't have access to each task's JoinHandle, so I couldn't use that. After some replumbing I fixed that so I simply iterate over all JoinHandle's and await them. Problem solved!

However; assuming I couldn't have done that -- is there some already-existing solution for this? I'm looking for something akin to tokio's Semaphore, but with the ability to .await until all permits have been dropped.

How about Tokio's TaskTracker?

2 Likes

Wow -- that's perfect. Thank you!

Clearly I need to take some time to do some spelunking in the tokio{,-util} docs.

I'm glad you like it. :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.