[][src]Crate throttle_timer

Throttle events and record event stats with a simple library

throttle_timer has no dependencies

ThrottleTimer struct is created with a max frequency and label

ThrottleTimer::new(Duration::from_secs(1_u64), &"Once every second");

Calling do_run() will check the last call time. If max frequency time has not passed the fn will return false. If max_frequency duration has passed since the last call then the fn will return true

Example

use std::time::Duration;

let mut break_timer: ThrottleTimer = ThrottleTimer::new(Duration::from_secs(1_u64), &"Break");
let do_break_flag = break_timer.do_run();

// Timers always run when no previous runs
assert!(do_break_flag == true);
if do_break_flag {
    println!("timer do run flag is set to true")
}

// Run flag false as no time has passed
assert!(break_timer.do_run() == false);

Structs

ThrottleTimer