Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ibraheemdev/awaitgroup
Wait for a collection of async tasks to finish.
https://github.com/ibraheemdev/awaitgroup
Last synced: 28 days ago
JSON representation
Wait for a collection of async tasks to finish.
- Host: GitHub
- URL: https://github.com/ibraheemdev/awaitgroup
- Owner: ibraheemdev
- License: mit
- Created: 2021-03-11T00:36:44.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-08-07T23:53:49.000Z (3 months ago)
- Last Synced: 2024-09-14T09:48:02.396Z (about 2 months ago)
- Language: Rust
- Size: 33.2 KB
- Stars: 32
- Watchers: 3
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `awaitgroup`
[](https://crates.io/crates/awaitgroup)
[](https://github.com/ibraheemdev/awaitgroup)
[](https://docs.rs/awaitgroup)A `WaitGroup` waits for a collection of asynchronous 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.```rust
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](https://docs.rs/awaitgroup) for more details.