Struct ratelimit::Ratelimit
[−]
[src]
pub struct Ratelimit { /* fields omitted */ }
Methods
impl Ratelimit
[src]
fn new() -> Ratelimit
fn configure() -> Config
create a new Config
for building a custom Ratelimit
Example
let mut r = Ratelimit::configure().build();
fn run(&mut self)
run the ratelimiter
Example
let mut r = Ratelimit::new(); let sender = r.clone_sender(); let _ = sender.try_send(()); r.run(); // invoke in a tight-loop in its own thread
fn clone_sender(&mut self) -> SyncSender<()>
return clone of SyncSender for client use
Example
let mut r = Ratelimit::new(); let sender = r.clone_sender(); match sender.try_send(()) { Ok(_) => { println!("not limited"); }, Err(_) => { println!("was limited"); }, }
fn block(&mut self, count: u32)
this call is the blocking API of Ratelimit
Example
let mut r = Ratelimit::new(); for i in -10..0 { println!("T {}...", i); r.block(1); } println!("Ignition!");