Struct throttler::simple::SimpleThrottler
[−]
[src]
pub struct SimpleThrottler { /* fields omitted */ }
Methods
impl SimpleThrottler
[src]
fn new(operations: u64, interval: Duration) -> SimpleThrottler
Constructs a new SimpleThrottler
. Takes as parameters the number of
operations allowed per time interval, and the length of the interval.
Examples
use throttler::simple::SimpleThrottler; use std::time::Duration; let throttler = SimpleThrottler::new(1000, Duration::new(1, 0));
fn wait(&mut self)
Waits until the throttler allows to make more operations. If no more operations are allowed in the current time interval, the throttler waits for it to end.
Examples
use throttler::simple::SimpleThrottler; use std::time::Duration; let mut throttler = SimpleThrottler::new(3, Duration::new(1, 0)); // This will print all numbers from 0 to 10 in bursts of 3. for i in 0..10 { throttler.wait(); println!("{}", i); }
fn restart(&mut self)
Restarts the throttler completely. After calling restart
the throttler
is restored to its initial state, like after the new
call.
Examples
use throttler::simple::SimpleThrottler; use std::time::Duration; let mut throttler = SimpleThrottler::new(3, Duration::new(1, 0)); // This will print all numbers from 0 to 10 together, because the // throttler always gets restarted. for i in 0..10 { throttler.wait(); println!("{}", i); throttler.restart() }