async-timer 0.7.4

Timers for Rust async story
Documentation

async-timer

Crates.io Documentation dependency status

Timer facilities for Rust's async story

Minimal Rust version: 1.36

Timed

async fn job() {
}

async fn do_job() {
    let work = unsafe {
        async_timer::Timed::platform_new_unchecked(job(), core::time::Duration::from_secs(1))
    };

    match work.await {
        Ok(_) => println!("I'm done!"),
        //You can retry by polling `expired`
        Err(expired) => println!("Job expired: {}", expired),
    }
}

Interval

async fn job() {
}

async fn do_a_while() {
    let mut times: u8 = 0;
    let mut interval = async_timer::Interval::platform_new(core::time::Duration::from_secs(1));

    while times < 5 {
        job().await;
        interval.as_mut().await;
        times += 1;
    }
}

Q&A

Q: When it is going to be async/await?

A: When async/await will become no_std