simple/
simple.rs

1use std::time::Duration;
2use throttle_timer::ThrottleTimer;
3
4fn main() {
5    let mut break_timer = ThrottleTimer::new(Duration::from_secs(10_u64), &"Break");
6    let mut val = 0_u8;
7    // timers always run when no previous runs
8    assert!(break_timer.run(&mut || val += 1));
9
10    for _ in 0..100 {
11        // timer will not run as 10 secs has not passed
12        // do run will return false
13        assert!(!break_timer.run(&mut || val += 1));
14    }
15    break_timer.print_stats();
16    assert_eq!(break_timer.total_calls(), &1);
17    assert_eq!(val, 1_u8);
18}