awaitgroup

Crates.ioawaitgroup
lib.rsawaitgroup
version0.7.0
sourcesrc
created_at2021-03-11 00:51:37.250685
updated_at2023-07-15 21:21:40.377361
descriptionWait for a collection of async tasks to finish.
homepage
repositoryhttps://github.com/ibraheemdev/awaitgroup
max_upload_size
id367036
size12,959
Ibraheem Ahmed (ibraheemdev)

documentation

README

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.

Commit count: 36

cargo fmt