pub struct BackpressureGuard { /* private fields */ }Expand description
Tracks in-flight work count and enforces a capacity limit.
§Guarantees
- Thread-safe via
Arc<Mutex<_>> try_acquireis non-blockingreleasedecrements the counter; no-op if counter is already 0- Optional soft limit emits a warning when depth reaches the threshold
Implementations§
Source§impl BackpressureGuard
impl BackpressureGuard
Sourcepub fn new(capacity: usize) -> Result<Self, AgentRuntimeError>
pub fn new(capacity: usize) -> Result<Self, AgentRuntimeError>
Create a new guard with the given capacity.
§Returns
Ok(BackpressureGuard)— on successErr(AgentRuntimeError::Orchestration)— ifcapacity == 0
Sourcepub fn with_soft_limit(self, soft: usize) -> Result<Self, AgentRuntimeError>
pub fn with_soft_limit(self, soft: usize) -> Result<Self, AgentRuntimeError>
Set a soft capacity threshold. When depth reaches this level, a warning is logged but the request is still accepted (up to hard capacity).
Sourcepub fn try_acquire(&self) -> Result<(), AgentRuntimeError>
pub fn try_acquire(&self) -> Result<(), AgentRuntimeError>
Try to acquire a slot.
Emits a warning when the soft limit is reached (if configured), but still accepts the request until hard capacity is exceeded.
§Returns
Ok(())— slot acquiredErr(AgentRuntimeError::BackpressureShed)— hard capacity exceeded
Sourcepub fn release(&self) -> Result<(), AgentRuntimeError>
pub fn release(&self) -> Result<(), AgentRuntimeError>
Release a previously acquired slot.
Sourcepub fn hard_capacity(&self) -> usize
pub fn hard_capacity(&self) -> usize
Return the hard capacity (maximum concurrent slots) configured for this guard.
Sourcepub fn depth(&self) -> Result<usize, AgentRuntimeError>
pub fn depth(&self) -> Result<usize, AgentRuntimeError>
Return the current depth.
Sourcepub fn soft_depth_ratio(&self) -> f32
pub fn soft_depth_ratio(&self) -> f32
Return the ratio of current depth to soft capacity as a value in [0.0, ∞).
Returns 0.0 if no soft limit has been configured.
Values above 1.0 mean the soft limit has been exceeded.
Trait Implementations§
Source§impl Clone for BackpressureGuard
impl Clone for BackpressureGuard
Source§fn clone(&self) -> BackpressureGuard
fn clone(&self) -> BackpressureGuard
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 Freeze for BackpressureGuard
impl RefUnwindSafe for BackpressureGuard
impl Send for BackpressureGuard
impl Sync for BackpressureGuard
impl Unpin for BackpressureGuard
impl UnsafeUnpin for BackpressureGuard
impl UnwindSafe for BackpressureGuard
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