pub struct ThresholdLoadBalancer<T>{ /* private fields */ }Expand description
Threshold-based load balancer that limits allocations per entry and handles failures.
Implementations§
Source§impl<T> ThresholdLoadBalancer<T>
impl<T> ThresholdLoadBalancer<T>
Sourcepub fn new(entries: Vec<(u64, u64, T)>) -> Self
pub fn new(entries: Vec<(u64, u64, T)>) -> Self
Create a new threshold load balancer with a fixed 1-second interval.
§Arguments
entries- A vector of tuples(max_count, max_error_count, value):max_count: Maximum number of allocations allowed per interval.max_error_count: Maximum number of errors allowed before disabling the entry.value: value.
Sourcepub fn new_interval(entries: Vec<(u64, u64, T)>, interval: Duration) -> Self
pub fn new_interval(entries: Vec<(u64, u64, T)>, interval: Duration) -> Self
Create a new threshold load balancer with a custom interval.
§Arguments
-
entries- A vector of tuples(max_count, max_error_count, value):max_count: Maximum number of allocations allowed per interval.max_error_count: Maximum number of errors allowed before disabling the entry.value: value.
-
interval- Duration after which all allocation/error counts are reset.
Sourcepub async fn update<F, R>(&self, handle: F) -> Result<()>
pub async fn update<F, R>(&self, handle: F) -> Result<()>
Execute a custom async update on the internal reference.
Sourcepub async fn alloc_skip(&self, skip_index: usize) -> (usize, T)
pub async fn alloc_skip(&self, skip_index: usize) -> (usize, T)
Allocate an entry, skipping the specified index if provided.
Sourcepub fn try_alloc_skip(&self, skip_index: usize) -> Option<(usize, T)>
pub fn try_alloc_skip(&self, skip_index: usize) -> Option<(usize, T)>
Try to allocate an entry immediately, skipping the specified index if provided.
Trait Implementations§
Source§impl<T> BoxLoadBalancer<T> for ThresholdLoadBalancer<T>
impl<T> BoxLoadBalancer<T> for ThresholdLoadBalancer<T>
Source§impl<T> Clone for ThresholdLoadBalancer<T>
impl<T> Clone for ThresholdLoadBalancer<T>
Source§fn clone(&self) -> ThresholdLoadBalancer<T>
fn clone(&self) -> ThresholdLoadBalancer<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for ThresholdLoadBalancer<T>
impl<T> !RefUnwindSafe for ThresholdLoadBalancer<T>
impl<T> Send for ThresholdLoadBalancer<T>
impl<T> Sync for ThresholdLoadBalancer<T>
impl<T> Unpin for ThresholdLoadBalancer<T>
impl<T> !UnwindSafe for ThresholdLoadBalancer<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