wait-for-me

Crates.iowait-for-me
lib.rswait-for-me
version0.3.0
sourcesrc
created_at2020-05-04 20:31:47.892689
updated_at2023-12-21 17:04:17.512632
descriptionAsync CountDownLatch
homepage
repositoryhttps://github.com/wolf4ood/wait-for-me
max_upload_size
id237537
size68,909
Enrico Risa (wolf4ood)

documentation

README

wait-for-me

Async CountDownLatch

Tests status Coverage status Download docs.rs docs

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(())
}
Commit count: 56

cargo fmt