pub struct Faucet<T> { /* private fields */ }
Expand description
A back-pressured queue limited in size that can be drained after signaling completion.
This queue implementation has the following characteristics:
- Based on
deadqueue::limited::Queue
- Has limited capacity with back-pressure on push
- Can signal completion by calling
end()
or by providing a cancellation token and callingcancel()
on it - Once completion is signaled, no additional values can be pushed while any values remaining in the queue can be drained
Implementations§
Source§impl<T> Faucet<T>
impl<T> Faucet<T>
Sourcepub fn new_with_cancellation(
max_len: usize,
cancellation: CancellationToken,
) -> Self
pub fn new_with_cancellation( max_len: usize, cancellation: CancellationToken, ) -> Self
Creates a new faucet with a maximum queue length and a cancellation source.
Providing an existing cancellation token is useful when you have a “parent” cancellation token.
Cancelling the token will prevent any additional values from being pushed onto the queue, and will drain any values already in the queue.
Sourcepub fn end(&self)
pub fn end(&self)
Cancels the faucet, preventing any additional values from being pushed onto the queue. Any values already in the queue will be drained.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Returns true if the faucet has been cancelled and has no more values remaining in the queue to be drained.
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Returns true if the faucet is either: (a) accepting values, or (b) is cancelled but has not been fully drained.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Returns true if the faucet has been cancelled and will not accept any additional values pushed onto the queue.
Sourcepub async fn push(&self, value: T) -> ControlFlow<(), ()>
pub async fn push(&self, value: T) -> ControlFlow<(), ()>
Pushes a value onto the queue or waits until space is available.
Sourcepub async fn try_push(&self, value: T) -> Result<(), T>
pub async fn try_push(&self, value: T) -> Result<(), T>
Attempts to push a value onto the queue, returning Err(value)
if the
queue is full or has been cancelled.
Sourcepub async fn next(&self) -> Option<T>
pub async fn next(&self) -> Option<T>
Attempts to pop a value from the queue, returning None
if the queue is
has been cancelled and finished draining.