Skip to content

Wait for a collection of async tasks to finish.

License

Notifications You must be signed in to change notification settings

DevNulPavel/awaitgroup

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AwaitGroup

Documentation Version License

An asynchronous implementation of a WaitGroup.

A WaitGroup waits for a collection of tasks to finish. The main task can create new workers and pass them to each of the tasks it wants to wait for. Then, each of the tasks calls done when it finishes executing. 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.

About

Wait for a collection of async tasks to finish.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%