pub struct Pacer { /* private fields */ }Expand description
Token Bucket Pacer
Thread-safe pacer that can be shared across async tasks.
Implementations§
Source§impl Pacer
impl Pacer
Sourcepub fn new(initial_rate_bps: u64) -> Self
pub fn new(initial_rate_bps: u64) -> Self
Create a new pacer with the given initial rate (bytes/sec).
Sourcepub fn try_consume(&self, bytes: u64) -> bool
pub fn try_consume(&self, bytes: u64) -> bool
Try to consume bytes tokens. Returns true if allowed, false if should wait.
Sourcepub fn time_until_available(&self, bytes: u64) -> Duration
pub fn time_until_available(&self, bytes: u64) -> Duration
How long to wait before bytes tokens are available.
Sourcepub fn set_enabled(&self, enabled: bool)
pub fn set_enabled(&self, enabled: bool)
Enable or disable pacing.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether pacing is enabled.
Sourcepub fn available_tokens(&self) -> u64
pub fn available_tokens(&self) -> u64
Current available tokens.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Pacer
impl RefUnwindSafe for Pacer
impl Send for Pacer
impl Sync for Pacer
impl Unpin for Pacer
impl UnsafeUnpin for Pacer
impl UnwindSafe for Pacer
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