pub struct Pusher<'a, T> { /* private fields */ }
Expand description
Queue endpoint for pushing data. Access to a Pusher
only gives you the
right to push data and enquire about push-related properties.
See the module docs for more details.
Implementations§
source§impl<'q, T> Pusher<'q, T>
impl<'q, T> Pusher<'q, T>
sourcepub fn can_push(&self) -> bool
pub fn can_push(&self) -> bool
Checks if there is room to push at least one item. Because the Pusher
endpoint has exclusive control over data movement into the queue, if
this returns true
, the condition will remain true until a push
or
try_push
happens through self
, or self
is dropped.
If this returns false
, of course, room may appear at any time if the
other end of the queue is popped.
sourcepub fn try_reserve(&mut self) -> Option<Entry<'q, T>>
pub fn try_reserve(&mut self) -> Option<Entry<'q, T>>
Checks if there is room to push at least one item, and if so, returns an
Entry
that entitles its holder to that queue slot.
If the queue is full, returns None
.
sourcepub async fn reserve<'s>(&'s mut self) -> Entry<'s, T>
pub async fn reserve<'s>(&'s mut self) -> Entry<'s, T>
Produces a future that resolves when there is enough space in the queue
to push one element. It resolves into an Entry
, which entitles the
holder to pushing an element without needing to check or await
. This
is a deliberate design choice – it means you can cancel the future
without losing the element you were trying to push.
The returned Entry
borrows self
exclusively. This means you must
use the Entry
, or drop it, before you can request another. This
prevents a deadlock, where you wait for a second permit that will never
emerge.
The future produced by reserve
also borrows self
exclusively. This
means you can’t simultaneously have two futures waiting for permits from
the same Pusher
. This wouldn’t necessarily be a bad thing, but we need
to maintain the exclusive borrow in order to pass it through to the
Entry
.
§Cancellation
Cancel Safety: Strict.
This does basically nothing if cancelled (it is intrinsically cancel-safe).