#waitgroup #notify #wake #futures #async

awaitgroup

Wait for a collection of async tasks to finish

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

#275 in Asynchronous

Download history 1053/week @ 2023-10-22 894/week @ 2023-10-29 1041/week @ 2023-11-05 1280/week @ 2023-11-12 1101/week @ 2023-11-19 1284/week @ 2023-11-26 1070/week @ 2023-12-03 1086/week @ 2023-12-10 1183/week @ 2023-12-17 668/week @ 2023-12-24 762/week @ 2023-12-31 799/week @ 2024-01-07 994/week @ 2024-01-14 985/week @ 2024-01-21 2371/week @ 2024-01-28 3502/week @ 2024-02-04

7,903 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