async-wg

Crates.ioasync-wg
lib.rsasync-wg
version0.1.2
sourcesrc
created_at2020-02-06 09:23:54.878386
updated_at2020-02-18 19:10:32.075308
descriptionAsync version WaitGroup for RUST.
homepage
repositoryhttps://github.com/jmjoy/async-wg.git
max_upload_size
id205429
size15,068
jmjoy (jmjoy)

documentation

README

async-wg

Rustc Version Actions Crate API

Async version WaitGroup for RUST.

Installation

With cargo add installed run:

$ cargo add -s async-wg

Examples

#[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;
}

Benchmarks

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)

License

The Unlicense.

Commit count: 18

cargo fmt