wait-for-me
Async CountDownLatch
Install
Install from crates.io
[dependencies]
wait-for-me = "0.1"
Example
with smol
```rust
use waitforme::CountDownLatch;
use smol::Task;
[smol_potat::main]
async fn main() -> Result<(), Box> {
let latch = CountDownLatch::new(10);
for _ in 0..10 {
let latch1 = latch.clone();
Task::spawn(async move {
latch1.count_down().await;
}).detach();
}
latch.wait().await;
Ok(())
}
```
with timeout
```rust
use smol::{Task, Timer};
use std::time::Duration;
use waitforme::CountDownLatch;
[smol_potat::main]
async fn main() -> Result<(), Box> {
let latch = CountDownLatch::new(10);
for _ in 0..10 {
let latch1 = latch.clone();
Task::spawn(async move {
Timer::after(Duration::fromsecs(3)).await;
latch1.countdown().await;
})
.detach();
}
let result = latch.waitfor(Duration::fromsecs(1)).await;
assert_eq!(false, result);
Ok(())
}
```