Crates.io | async-wg |
lib.rs | async-wg |
version | 0.1.2 |
source | src |
created_at | 2020-02-06 09:23:54.878386 |
updated_at | 2020-02-18 19:10:32.075308 |
description | Async version WaitGroup for RUST. |
homepage | |
repository | https://github.com/jmjoy/async-wg.git |
max_upload_size | |
id | 205429 |
size | 15,068 |
Async version WaitGroup for RUST.
With cargo add installed run:
$ cargo add -s async-wg
#[tokio::main]
async fn main() {
use async_wg::WaitGroup;
// Create a new wait group.
let wg = WaitGroup::new();
for _ in 0..10 {
let wg = wg.clone();
// Add count n.
wg.add(1).await;
tokio::spawn(async move {
// Do some work.
// Done count 1.
wg.done().await;
});
}
// Wait for done count is equal to add count.
wg.await;
}
Simple benchmark comparison run on github actions.
Code: benchs/main.rs
test bench_join_handle ... bench: 34,485 ns/iter (+/- 18,969)
test bench_wait_group ... bench: 36,916 ns/iter (+/- 7,555)
The Unlicense.