#events #arceos #expire #timer #timer-list

no-std timer_list

A list of timed events that will be triggered sequentially when the timer expires

1 unstable release

0.1.0 Jul 17, 2024

#469 in Date and time

Download history 422/week @ 2024-12-15 615/week @ 2024-12-22 634/week @ 2024-12-29 386/week @ 2025-01-05 199/week @ 2025-01-12 144/week @ 2025-01-19 36/week @ 2025-01-26 329/week @ 2025-02-02 320/week @ 2025-02-09 280/week @ 2025-02-16 253/week @ 2025-02-23 600/week @ 2025-03-02 1540/week @ 2025-03-09 958/week @ 2025-03-16 1079/week @ 2025-03-23 1079/week @ 2025-03-30

4,795 downloads per month

GPL-3.0-or-later OR Apache-2…

9KB
152 lines

timer_list

Crates.io Docs.rs CI

A list of timed events that will be triggered sequentially when the timer expires.

Examples

use timer_list::{TimerEvent, TimerEventFn, TimerList};
use std::time::{Duration, Instant};

let mut timer_list = TimerList::new();

// set a timer that will be triggered after 1 second
let start_time = Instant::now();
timer_list.set(Duration::from_secs(1), TimerEventFn::new(|now| {
    println!("timer event after {:?}", now);
}));

while !timer_list.is_empty() {
    // check if there is any event that is expired
    let now = Instant::now().duration_since(start_time);
    if let Some((deadline, event)) = timer_list.expire_one(now) {
        // trigger the event, will print "timer event after 1.00s"
        event.callback(now);
        break;
    }
    std::thread::sleep(Duration::from_millis(10)); // relax the CPU
}

No runtime deps