Struct ratelimit::Handle
[−]
[src]
pub struct Handle { /* fields omitted */ }
Handler for a multi-threaded rate-limiter.
Methods
impl Handle
[src]
fn wait(&mut self)
[src]
Block for 1 token
Examples
let mut limiter = Builder::default().build(); let mut handle = limiter.make_handle(); thread::spawn(move || { limiter.run() }); let mut threads = Vec::new(); for i in 0..2 { let mut handle = handle.clone(); threads.push(thread::spawn(move || { for x in 0..5 { handle.wait(); println!("."); } })); }
fn wait_for(&mut self, count: usize)
[src]
Block for count
tokens
Examples
let mut limiter = Builder::default().build(); let mut handle = limiter.make_handle(); thread::spawn(move || { limiter.run() }); let mut threads = Vec::new(); for i in 0..2 { let mut handle = handle.clone(); threads.push(thread::spawn(move || { for x in 0..5 { handle.wait_for(1); println!("."); } })); }
fn try_wait(&mut self) -> Result<(), ()>
[src]
Non-blocking wait for one token. Returns Ok(()) if no wait required. Returns Err(()) if wait would block.
Examples
let mut limiter = Builder::new().build(); let mut handle = limiter.make_handle(); if handle.try_wait().is_ok() { println!("token granted"); } else { println!("would block"); }
fn try_wait_for(&mut self, count: usize) -> Result<(), ()>
[src]
Non-blocking wait for count
token.
Returns Ok(()) if no wait required.
Returns Err(()) if wait would block.
Examples
let mut limiter = Builder::new().build(); let mut handle = limiter.make_handle(); if handle.try_wait_for(2).is_ok() { println!("tokens granted"); } else { println!("would block"); }
Trait Implementations
impl Clone for Handle
[src]
fn clone(&self) -> Handle
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more