Skip to content

Timer facilities for Rust's async story

License

Notifications You must be signed in to change notification settings

krircc/async-timer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Timer facilities for Rust's async story

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%