pub struct RateLimiter { /* private fields */ }Expand description
Window quotas for one API surface: a general bucket every request passes, then the buckets of the first row its method and path match.
Built by WindowQuotaTable; a venue’s crate builds one for each of its
API surfaces. A clone shares the buckets and the
Hold.
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn begin_cooldown(&self, delay: Duration)
pub fn begin_cooldown(&self, delay: Duration)
Hold every request on this limiter for delay: Hold::extend on
its hold, which extends a hold in force but never shortens one.
The send loop holds through Throttle::hold, which calls this, when
its policy decides a response holds the client. Reach for this directly
only when driving the limiter from a transport this crate does not own.
Sourcepub fn hold(&self) -> &Hold
pub fn hold(&self) -> &Hold
The hold every request on this limiter waits out, to share with another layer.
Sourcepub async fn acquire(&self, path: &str, method: Option<&Method>)
pub async fn acquire(&self, path: &str, method: Option<&Method>)
Await the appropriate limiter(s) for this endpoint.
Waits out any hold a previous 429 imposed, then awaits the default (general) limiter, then additionally awaits the first matching endpoint-specific limiter (burst + sustained), then waits out the hold again, in case it moved while this call waited on a bucket. Every wait sleeps on the hold’s runtime.
Sourcepub fn effective_quota(
&self,
method: &Method,
path: &str,
) -> Vec<EffectiveQuota>
pub fn effective_quota( &self, method: &Method, path: &str, ) -> Vec<EffectiveQuota>
The quotas a request is held to, in the order
acquire awaits them: the general bucket first, then
the buckets of the first row method and path match.
Trait Implementations§
Source§impl Clone for RateLimiter
impl Clone for RateLimiter
Source§impl Debug for RateLimiter
impl Debug for RateLimiter
Source§impl Throttle for RateLimiter
impl Throttle for RateLimiter
Source§fn observe(
&self,
_charge: &Charge,
_response: &ResponseMeta<'_>,
_attempt: &AttemptInfo,
)
fn observe( &self, _charge: &Charge, _response: &ResponseMeta<'_>, _attempt: &AttemptInfo, )
Nothing to record: the buckets model the published quota, not what a response says.