pub struct Receiver<T> { /* private fields */ }
Expand description
The Single Receiver of a Jiffy-Queue, created by calling queue
Implementations
sourceimpl<T> Receiver<T>
impl<T> Receiver<T>
sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Checks if the Queue has been closed by the Producers
Note
Even when this method indicates that the Queue has been closed, there
may still be Elements left in the Queue and therefore you should
attempt to dequeue the next Element and only when you get back an Error
with DequeueError::Closed
can you be sure that there is nothing
left in the Queue and you can savely discard it.
Example:
let (mut rx, tx) = jiffy::queue::<usize>();
// The Producer side gets dropped and is therefore considered closed
drop(tx);
assert_eq!(true, rx.is_closed());
sourcepub fn try_dequeue(&mut self) -> Result<T, DequeueError>
pub fn try_dequeue(&mut self) -> Result<T, DequeueError>
Attempts to dequeue the next entry in the Queue
Example
let (mut rx, tx) = jiffy::queue::<usize>();
// Insert one Element into the Queue
tx.enqueue(13).unwrap();
// Retrieve the first and only Element from the Queue
assert_eq!(Ok(13), rx.try_dequeue());
// Attempt to get the next Element, but there is none so we get
// the right Error indicating that there is no Element to dequeue at
// that moment
assert_eq!(Err(DequeueError::Empty), rx.try_dequeue());
sourcepub fn dequeue(&mut self) -> Option<T>
pub fn dequeue(&mut self) -> Option<T>
This is a simple blocking dequeue. This is definetly not lock free anymore and will simply spin and try to dequeue an item over and over again.
Behaviour
This function will block until it either successfully dequeues an item
from the Queue and will then return Some(data)
or until the Queue has
been closed by the other Side, in which case it will return None
sourcepub fn iter_mut<'queue, 'iter>(&'queue mut self) -> RefIter<'iter, T>ⓘNotable traits for RefIter<'queue, T>impl<'queue, T> Iterator for RefIter<'queue, T> type Item = T;
where
'queue: 'iter,
pub fn iter_mut<'queue, 'iter>(&'queue mut self) -> RefIter<'iter, T>ⓘNotable traits for RefIter<'queue, T>impl<'queue, T> Iterator for RefIter<'queue, T> type Item = T;
where
'queue: 'iter,
Returns a RefIter for the Queue, this allows you to still use the Queue-Receiver once the Iterator has been dropped
Trait Implementations
sourceimpl<'queue, T> IntoIterator for &'queue mut Receiver<T>
impl<'queue, T> IntoIterator for &'queue mut Receiver<T>
sourceimpl<T> IntoIterator for Receiver<T>
impl<T> IntoIterator for Receiver<T>
impl<T> Send for Receiver<T>
impl<T> Sync for Receiver<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for Receiver<T>
impl<T> Unpin for Receiver<T>
impl<T> !UnwindSafe for Receiver<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more