Crate ratelim

Source
Expand description

Simplistic rate limiter.

§Examples

// We don't want to overwater plants. Twice a second should be fine?
let mut lim_water_plants = RateLimiter::new(Duration::from_millis(500));

let mut n = 0;
for _ in 0..5 {
    lim_water_plants.run(|| {
        println!("Watering plants... 🌱🔫");
        n += 1;
    });
    thread::sleep(Duration::from_millis(200));
}
assert_eq!(n, 2);

Structs§

RateLimiter
Allows to run the operation at most once per the cooldown period.
Timer
A timer that calls a function on drop with the elapsed time.