timer_list 0.1.0

A list of timed events that will be triggered sequentially when the timer expires
Documentation
  • Coverage
  • 100%
    13 out of 13 items documented1 out of 12 items with examples
  • Size
  • Source code size: 10.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.86 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • arceos-org/timer_list
    0 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • equation314 github:arceos-org:core

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
}