pub struct RequestQuota { /* private fields */ }Expand description
RequestQuota provides a short-lived, ephemeral budget for a single cache operation.
While [ThreadContext] manages the hardware-level timing (how long to wait),
RequestQuota manages the logical retries (how many times to try). It acts as
a safety valve to prevent “Livelock”—a scenario where a thread enters an
infinite retry loop because a high-contention slot never becomes available.
§Characteristics
- Stack-Allocated: Designed to be created on the stack at the start of an operation.
- Single-Use: Typically discarded once the
pushorpopoperation completes. - Deterministic: Ensures that an operation will eventually return (either with success or a “Busy” error) within a bounded number of attempts.
Implementations§
Source§impl RequestQuota
impl RequestQuota
Sourcepub fn new(remaining: usize) -> Self
pub fn new(remaining: usize) -> Self
Creates a new quota with the specified number of allowed retries.
§Parameters
remaining: The maximum number of failed atomic attempts to tolerate before aborting the request.
Sourcepub fn consume(&mut self) -> bool
pub fn consume(&mut self) -> bool
Attempts to consume one unit of the retry budget.
This should be called every time a contention-sensitive operation (like a Compare-And-Swap) fails, but before performing a backoff yield.
§Returns
true: Budget is available; the operation should retry.false: Budget is exhausted; the operation should abort to prevent stalling the system.
pub fn has_attempts(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RequestQuota
impl RefUnwindSafe for RequestQuota
impl Send for RequestQuota
impl Sync for RequestQuota
impl Unpin for RequestQuota
impl UnsafeUnpin for RequestQuota
impl UnwindSafe for RequestQuota
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