pub struct BackpressureEnforcer { /* private fields */ }Expand description
Caps how many un-acked jobs a topic may have outstanding.
A slot is taken by try_enqueue and returned by
dec_finished, so the cap holds only if the caller
pairs them. Nothing here releases a slot on its own: the enforcer cannot know
when a handler finished.
Implementations§
Source§impl BackpressureEnforcer
impl BackpressureEnforcer
Sourcepub fn new(max_inflight: usize) -> Self
pub fn new(max_inflight: usize) -> Self
Creates an enforcer that allows max_inflight un-acked jobs per topic.
A cap of zero would reject every enqueue, so it is clamped to one.
Sourcepub async fn try_enqueue<Q: Queue + ?Sized>(
&self,
queue: &Q,
topic: &str,
payload: Vec<u8>,
) -> Result<(), BackpressureError>
pub async fn try_enqueue<Q: Queue + ?Sized>( &self, queue: &Q, topic: &str, payload: Vec<u8>, ) -> Result<(), BackpressureError>
Enqueues payload if the topic has room, returning
BackpressureError::LimitReached otherwise.
The slot is released again if the queue itself rejects the job, so a failing backend cannot leak capacity.
Sourcepub fn dec_finished(&self, topic: &str)
pub fn dec_finished(&self, topic: &str)
Returns one slot for topic after a job is acked or nacked.
Saturates at zero, so an unmatched call cannot wrap the counter and hand the topic unlimited capacity.
Auto Trait Implementations§
impl !Freeze for BackpressureEnforcer
impl RefUnwindSafe for BackpressureEnforcer
impl Send for BackpressureEnforcer
impl Sync for BackpressureEnforcer
impl Unpin for BackpressureEnforcer
impl UnsafeUnpin for BackpressureEnforcer
impl UnwindSafe for BackpressureEnforcer
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