7 releases (breaking)

0.7.0 Jul 15, 2023
0.6.0 Mar 21, 2021
0.5.0 Mar 12, 2021
0.4.0 Mar 11, 2021
0.1.0 Mar 11, 2021

#338 in Asynchronous

Download history 1118/week @ 2023-12-14 805/week @ 2023-12-21 492/week @ 2023-12-28 873/week @ 2024-01-04 790/week @ 2024-01-11 897/week @ 2024-01-18 1113/week @ 2024-01-25 3179/week @ 2024-02-01 2593/week @ 2024-02-08 3067/week @ 2024-02-15 4815/week @ 2024-02-22 5542/week @ 2024-02-29 5168/week @ 2024-03-07 5791/week @ 2024-03-14 4292/week @ 2024-03-21 3701/week @ 2024-03-28

19,749 downloads per month
Used in 2 crates

MIT license

11KB
168 lines

awaitgroup

Documentation Version License

A WaitGroup waits for a collection of async tasks to finish.

The main task can create new workers and pass them to each of the tasks it wants to wait for. Each of the tasks calls done when it finishes executing, and the main task can call wait to block until all registered workers are done.

use awaitgroup::WaitGroup;

#[tokio::main]
async fn main() {
   let mut wg = WaitGroup::new();

   for _ in 0..5 {
       // Create a new worker.
       let worker = wg.worker();

       tokio::spawn(async {
           // Do some work...

           // This task is done all of its work.
           worker.done();
       });
   }

   // Block until all other tasks have finished their work.
   wg.wait().await;
}

See the documentation for more details.

No runtime deps