Skip to main content

Throttle

Trait Throttle 

Source
pub trait Throttle: Send + Sync {
    // Required methods
    fn acquire(
        &self,
        meta: &RequestMeta<'_>,
    ) -> impl Future<Output = Result<Charge, Refused>> + Send;
    fn observe(
        &self,
        charge: &Charge,
        response: &ResponseMeta<'_>,
        attempt: &AttemptInfo,
    );
    fn hold(&self, delay: Duration);
}
Expand description

Charges each attempt, sees each response, and holds every request on it.

One throttle is shared by every client that shares a budget, and its hold with it.

Required Methods§

Source

fn acquire( &self, meta: &RequestMeta<'_>, ) -> impl Future<Output = Result<Charge, Refused>> + Send

Wait until the request may be sent, and charge it.

Waits out any hold before charging, and again if the hold moved while this call waited on a bucket of its own.

§Errors

Refused when a cost exceeds what a layer can ever hold. Nothing is sent, and the request is not retried.

Source

fn observe( &self, charge: &Charge, response: &ResponseMeta<'_>, attempt: &AttemptInfo, )

See a response to an attempt acquire charged. Runs on every response, before the policy decides. Records counts and tiers only.

Source

fn hold(&self, delay: Duration)

Hold every request on this throttle for delay. A hold only ever extends.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<DYNOSAUR> Throttle for &DYNOSAUR
where DYNOSAUR: ?Sized + Throttle, Self: Send + Sync,

Source§

fn acquire( &self, meta: &RequestMeta<'_>, ) -> impl Future<Output = Result<Charge, Refused>> + Send

Source§

fn observe( &self, charge: &Charge, response: &ResponseMeta<'_>, attempt: &AttemptInfo, )

Source§

fn hold(&self, delay: Duration)

Source§

impl<DYNOSAUR> Throttle for &mut DYNOSAUR
where DYNOSAUR: ?Sized + Throttle, Self: Send + Sync,

Source§

fn acquire( &self, meta: &RequestMeta<'_>, ) -> impl Future<Output = Result<Charge, Refused>> + Send

Source§

fn observe( &self, charge: &Charge, response: &ResponseMeta<'_>, attempt: &AttemptInfo, )

Source§

fn hold(&self, delay: Duration)

Source§

impl<DYNOSAUR> Throttle for Box<DYNOSAUR>
where DYNOSAUR: ?Sized + Throttle, Self: Send + Sync,

Source§

fn acquire( &self, meta: &RequestMeta<'_>, ) -> impl Future<Output = Result<Charge, Refused>> + Send

Source§

fn observe( &self, charge: &Charge, response: &ResponseMeta<'_>, attempt: &AttemptInfo, )

Source§

fn hold(&self, delay: Duration)

Implementors§

Source§

impl Throttle for NoThrottle

Source§

impl Throttle for RateLimiter

Counts requests: each attempt is charged one request against the general bucket and its row’s buckets, found from the method and path, and hold extends the limiter’s Hold.

Source§

impl<'dynosaur_struct> Throttle for DynThrottle<'dynosaur_struct>