5 unstable releases

0.3.0 Dec 21, 2023
0.2.0 May 25, 2020
0.1.2 May 6, 2020
0.1.1 May 6, 2020
0.1.0 May 4, 2020

#379 in Asynchronous

Download history 41/week @ 2023-12-05 184/week @ 2023-12-12 114/week @ 2023-12-19 51/week @ 2024-01-02 144/week @ 2024-01-09 234/week @ 2024-01-16 198/week @ 2024-01-23 308/week @ 2024-01-30 440/week @ 2024-02-06 590/week @ 2024-02-13 315/week @ 2024-02-20 342/week @ 2024-02-27 370/week @ 2024-03-05 222/week @ 2024-03-12 193/week @ 2024-03-19

1,158 downloads per month
Used in 2 crates

Apache-2.0

19KB
352 lines

wait-for-me

Async CountDownLatch

Install

Install from crates.io

[dependencies]
wait-for-me = "0.1"

Example

with smol

use wait_for_me::CountDownLatch;
use smol::Task;


#[smol_potat::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    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

use smol::{Task, Timer};
use std::time::Duration;
use wait_for_me::CountDownLatch;

#[smol_potat::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let latch = CountDownLatch::new(10);
    for _ in 0..10 {
        let latch1 = latch.clone();
        Task::spawn(async move {
            Timer::after(Duration::from_secs(3)).await;
            latch1.count_down().await;
        })
        .detach();
    }
    let result = latch.wait_for(Duration::from_secs(1)).await;

    assert_eq!(false, result);

    Ok(())
}

Dependencies

~1.5MB
~24K SLoC