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

wag

类似于Rust中的sync.WaitGroup实现。 (sync/async)

3个版本 (破坏性更新)

0.3.0 2022年12月5日
0.2.0 2022年12月5日
0.1.0 2022年12月4日

#1198 in 异步

MIT/Apache

7KB

WAG

类似于Rust中的sync.WaitGroup实现。 (sync/async)

CI Crates.io Licensed Twitter

| 示例 | 文档 | 最新笔记 |

wag = "0.3.0"

如何使用,

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;

无运行时依赖