throttle-timer

Crates.iothrottle-timer
lib.rsthrottle-timer
version1.0.0
sourcesrc
created_at2019-11-06 08:43:09.257618
updated_at2019-11-08 05:11:00.317131
descriptionThrottle events and record event stats with a simple library
homepagehttps://github.com/benjaminmcdonald/rust-throttle_timer
repositoryhttps://github.com/benjaminmcdonald/rust-throttle_timer
max_upload_size
id178538
size12,828
Ben (benjaminmcdonald)

documentation

README

Rust throttle_timer

Simple Rust library to throttle events and record event stats

Docs Build Status Coverage Status Current Crates.io Version License

Install Cargo.toml

throttle-timer = "1.0.0"

Example use

use std::time::Duration;
use throttle_timer::ThrottleTimer;

let mut throttled_fn = ThrottleTimer::new(Duration::from_secs(10_u64), &"throttled_fn");
let mut val = 0_u8;

// timers always run when no previous runs
throttled_fn.run(&mut || val += 1);
for _ in 0..100 {
    // timer will not run as 10 secs has not passed
    // do run will return false
    throttled_fn.run(&mut || val += 1);
}

throttled_fn.print_stats();
// throttled_fn called 0/sec, total calls 1, has been running for 10us

assert_eq!(throttled_fn.total_calls(), &1);
assert_eq!(val, 1_u8);
Commit count: 20

cargo fmt