pub struct Throttle<T: Unsigned + AddAssign + Copy + PartialOrd> { /* private fields */ }Implementations§
Source§impl<T: Unsigned + AddAssign + Copy + PartialOrd> Throttle<T>
impl<T: Unsigned + AddAssign + Copy + PartialOrd> Throttle<T>
pub fn new(max_per_period: T, period: Duration) -> Self
Sourcepub fn per_second(max_per_period: T) -> Self
pub fn per_second(max_per_period: T) -> Self
Equivalent to
Throttle::new(max_per_period, Duration::from_secs(1))Sourcepub fn per_minute(max_per_period: T) -> Self
pub fn per_minute(max_per_period: T) -> Self
Equivalent to
Throttle::new(max_per_period, Duration::from_secs(60))Sourcepub async fn advance(&mut self) -> T
pub async fn advance(&mut self) -> T
Advances the throttle by 1, waiting if the throttle has been exhausted
Sourcepub async fn advance_by(&mut self, by: T) -> T
pub async fn advance_by(&mut self, by: T) -> T
Advances the throttle by the given amount, waiting if the throttle has been exhausted
Sourcepub async fn wait_if_exhausted(&self)
pub async fn wait_if_exhausted(&self)
If throttle period has been exhausted, waits for the period to end
otherwise returns immediately
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Throttle<T>where
T: Freeze,
impl<T> RefUnwindSafe for Throttle<T>where
T: RefUnwindSafe,
impl<T> Send for Throttle<T>where
T: Send,
impl<T> Sync for Throttle<T>where
T: Sync,
impl<T> Unpin for Throttle<T>where
T: Unpin,
impl<T> UnwindSafe for Throttle<T>where
T: UnwindSafe,
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