#wake #wait #sync #wait-group #async

wag

Go like sync.WaitGroup implementation in Rust. (sync/async)

3 releases (breaking)

0.3.0 Dec 5, 2022
0.2.0 Dec 5, 2022
0.1.0 Dec 4, 2022

#980 in Asynchronous

MIT/Apache

7KB

WAG

Go like sync.WaitGroup implementation in Rust. (sync/async)

CI Crates.io Licensed Twitter

| Examples | Docs | Latest Note |

wag = "0.3.0"

How to use,

use wag::WaitGroup;

let wg = WaitGroup::new();
for _ in 0..10 {
    let w = wg.add();

    thread::spawn(move || {
        // ...
        w.done();
    });

});
wg.wait(); // or wg.async_wait().await;
for w in wg.adds::<10>() {

    thread::spawn(move || {
        // ...
        w.done();
    });

});
wg.wait(); // or wg.async_wait().await;
let [w1, w2, w3] = wg.adds();

thread::spawn(move || {
    // ...
    w1.done();
});

thread::spawn(move || {
    // ...
    w2.done();
});

thread::spawn(move || {
    // ...
    w3.done();
});

wg.wait(); // or wg.async_wait().await;
wg.adds_iter::<10>().enumerate().for_each(|(i, w)| {

    thread::spawn(move || {
        // ... with i
        w.done();
    });

});
wg.wait(); // or wg.async_wait().await;

No runtime deps