pub struct BudgetedQueue<T> { /* private fields */ }Expand description
Represents budgeted queue.
Implementations§
Source§impl<T> BudgetedQueue<T>
impl<T> BudgetedQueue<T>
Sourcepub fn new(budget: ResourceBudget) -> Self
pub fn new(budget: ResourceBudget) -> Self
Creates a new BudgetedQueue.
Sourcepub fn is_same_queue(&self, other: &Self) -> bool
pub fn is_same_queue(&self, other: &Self) -> bool
Returns whether two handles refer to the same physical queue.
Sourcepub fn try_push(
&self,
item: T,
retained_bytes: usize,
class: BudgetClass,
) -> QueuePushOutcome<T>
pub fn try_push( &self, item: T, retained_bytes: usize, class: BudgetClass, ) -> QueuePushOutcome<T>
Attempts to push.
Sourcepub fn try_push_budgeted(
&self,
item: T,
permit: ResourcePermit,
) -> Result<QueuePushOutcome<T>, ForeignPermit<T>>
pub fn try_push_budgeted( &self, item: T, permit: ResourcePermit, ) -> Result<QueuePushOutcome<T>, ForeignPermit<T>>
Pushes an item whose retained bytes are already charged by permit.
The permit is transferred into the queue, so an admission at the
caller’s own ingress boundary and the queue retention charge the shared
ancestor chain exactly once. A permit acquired from an ancestor of this
queue’s budget is rebound to the queue before it is retained, which is
the difference between this entry point and the ones that acquire their
own permit from retained_bytes.
A rejection returns the item and releases the transferred charge, which matches the entry points that acquire their own permit: an item that was not retained holds no reservation.
§Errors
Returns ForeignPermit with the item and its unchanged permit when
permit does not belong to this queue’s budget tree. The permit still
holds the caller’s charge, so it is handed back instead of dropped.
Sourcepub fn try_push_data(
&self,
item: T,
retained_bytes: usize,
) -> QueuePushOutcome<T>
pub fn try_push_data( &self, item: T, retained_bytes: usize, ) -> QueuePushOutcome<T>
Attempts to push data.
Sourcepub fn try_push_control(
&self,
item: T,
retained_bytes: usize,
) -> QueuePushOutcome<T>
pub fn try_push_control( &self, item: T, retained_bytes: usize, ) -> QueuePushOutcome<T>
Attempts to push control.
Sourcepub async fn push_until(
&self,
item: T,
retained_bytes: usize,
class: BudgetClass,
deadline: Instant,
) -> QueuePushOutcome<T>
pub async fn push_until( &self, item: T, retained_bytes: usize, class: BudgetClass, deadline: Instant, ) -> QueuePushOutcome<T>
Pushes one item, waiting for count and byte capacity until an absolute
Tokio deadline when this queue uses FullPolicy::WaitUntilDeadline.
Other full policies retain their existing immediate behavior. Rate exhaustion remains an immediate rejection because capacity-release notifications do not represent token refill time.
Every rejection contains the original item.
Sourcepub fn try_pop(&self) -> Option<T>
pub fn try_pop(&self) -> Option<T>
Removes one item and releases its reservation before returning the payload.
Use Self::try_pop_budgeted when processing must retain the charge
after the item leaves the queue.
Sourcepub fn try_pop_budgeted(&self) -> Option<BudgetedItem<T>>
pub fn try_pop_budgeted(&self) -> Option<BudgetedItem<T>>
Removes one item while transferring its reservation to the caller.
The charge remains until the returned BudgetedItem or its permit is
dropped, consumed, or rebound. Queue depth alone does not measure the
number of outstanding reservations.
Sourcepub fn retain(&self, keep: impl FnMut(&T) -> bool) -> usize
pub fn retain(&self, keep: impl FnMut(&T) -> bool) -> usize
Retains queued items that satisfy keep and releases the resource
permits owned by every removed item.
The relative order of retained items is preserved.
Sourcepub async fn recv(&self) -> Option<T>
pub async fn recv(&self) -> Option<T>
Asynchronously receives a payload, releasing its reservation on return.
Returns None after closed admission and queued work have drained.
Sourcepub async fn recv_budgeted(&self) -> Option<BudgetedItem<T>>
pub async fn recv_budgeted(&self) -> Option<BudgetedItem<T>>
Asynchronously receives an item with its reservation still attached.
Returns None after closed admission and queued work have drained.
Cancellation of this wait does not consume a queued item.
Sourcepub fn snapshot(&self) -> QueueSnapshot
pub fn snapshot(&self) -> QueueSnapshot
Returns the snapshot.