RateLimiter

Trait RateLimiter 

Source
pub trait RateLimiter: Send + Sync {
    // Required methods
    fn acquire<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn adjust<'life0, 'life1, 'async_trait>(
        &'life0 self,
        response: &'life1 Response,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn current_delay<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Duration> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for asynchronous, stateful rate limiters.

Required Methods§

Source

fn acquire<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Blocks until a request is allowed to proceed.

Source

fn adjust<'life0, 'life1, 'async_trait>( &'life0 self, response: &'life1 Response, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Adjusts the rate limit based on the response.

Source

fn current_delay<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Duration> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns the current delay between requests.

Implementors§