Struct rate_limiter::SleepingRateLimiter
source · pub struct SleepingRateLimiter {
rate_limiter: TokenBucket,
}
Expand description
Allows to limit access to some resource. Given a preferred rate (units of something) and last used amount of units of some resource, it calculates how long we should delay our next access to that resource in order to satisfy that rate.
Fields§
§rate_limiter: TokenBucket
Implementations§
source§impl SleepingRateLimiter
impl SleepingRateLimiter
sourcepub fn new(rate_per_second: usize) -> Self
pub fn new(rate_per_second: usize) -> Self
Constructs a instance of SleepingRateLimiter with given target rate-per-second.
sourcepub async fn rate_limit(self, read_size: usize) -> Self
pub async fn rate_limit(self, read_size: usize) -> Self
Given read_size
, that is an amount of units of some governed resource, delays return of Self
to satisfy configure
rate.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for SleepingRateLimiter
impl Send for SleepingRateLimiter
impl Sync for SleepingRateLimiter
impl Unpin for SleepingRateLimiter
impl UnwindSafe for SleepingRateLimiter
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more