RateLimiter

Trait RateLimiter 

Source
pub trait RateLimiter: Debug + Sync {
    // Required methods
    fn acquire<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Token> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn acquire_timeout<'life0, 'async_trait>(
        &'life0 self,
        duration: Duration,
    ) -> Pin<Box<dyn Future<Output = Option<Token>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn release<'life0, 'async_trait>(
        &'life0 self,
        token: Token,
        outcome: Option<RequestOutcome>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Controls the rate of requests over time.

Rate limiting is achieved by checking if a request is allowed based on the current rate limit algorithm. The limiter tracks request patterns and adjusts limits dynamically based on observed success/failure rates and response times.

Required Methods§

Source

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

Acquire permission to make a request. Waits until a token is available.

Source

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

Acquire permission to make a request with a timeout. Returns a token if successful.

Source

fn release<'life0, 'async_trait>( &'life0 self, token: Token, outcome: Option<RequestOutcome>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Release the token and record the outcome of the request. The response time is calculated from when the token was acquired.

Implementors§