pub struct Window<T>{ /* private fields */ }Expand description
Sliding-window load balancer: each entry has a per-interval allocation cap.
Counts reset every interval (default 1 second); entries with max_count == 0
are unlimited.
Implementations§
Source§impl<T> Window<T>
impl<T> Window<T>
Sourcepub fn new(entries: Vec<(u64, T)>) -> Self
pub fn new(entries: Vec<(u64, T)>) -> Self
Create a Window with a 1-second reset interval.
Each tuple is (max_count, value) — max_count == 0 means unlimited.
Sourcepub fn new_interval(entries: Vec<(u64, T)>, interval: Duration) -> Self
pub fn new_interval(entries: Vec<(u64, T)>, interval: Duration) -> Self
Create a Window with a custom reset interval.
Sourcepub async fn update<F, R, N>(&self, handler: F) -> Result<N>
pub async fn update<F, R, N>(&self, handler: F) -> Result<N>
Run an async callback with access to the internal state.
Sourcepub async fn update_timer<F, R>(
&self,
handler: F,
interval: Duration,
) -> Result<JoinHandle<()>>
pub async fn update_timer<F, R>( &self, handler: F, interval: Duration, ) -> Result<JoinHandle<()>>
Spawn a background task that calls handler every interval.
The handler is called once immediately; if that initial call fails
the error is returned and no background task is spawned.
Returns a JoinHandle that can be aborted to stop the timer.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Window<T>
impl<T> !UnwindSafe for Window<T>
impl<T> Freeze for Window<T>
impl<T> Send for Window<T>
impl<T> Sync for Window<T>
impl<T> Unpin for Window<T>
impl<T> UnsafeUnpin for Window<T>
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