Crates.io | async-timer |
lib.rs | async-timer |
version | 1.0.0-beta.15 |
source | src |
created_at | 2019-04-21 13:26:28.130518 |
updated_at | 2024-09-29 00:29:35.724975 |
description | Timers for Rust async story |
homepage | |
repository | https://github.com/DoumanAsh/async-timer |
max_upload_size | |
id | 129246 |
size | 67,874 |
Timer facilities for Rust's async story
Regular timers that do not rely on async event loop tend to be on par with user space timers
like in tokio
.
If that's not suitable for you you should enable event loop based timers which in most cases
give you the most accurate timers possible on unix platforms (See features.)
tokio1
- Enables event loop based timers using tokio, providing higher resolution timers on unix platforms.c_wrapper
- Uses C shim to create bindings to platform API, which may be more reliable than libc
.std
- Enables usage of std types (e.g. Error)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),
}
}
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.wait().await;
times += 1;
}
}