Struct bounded_spsc_queue::Consumer
[−]
[src]
pub struct Consumer<T> { /* fields omitted */ }
A handle to the queue which allows consuming values from the buffer
Methods
impl<T> Consumer<T>
[src]
fn pop(&self) -> T
Pop a value off the queue.
If the buffer contains values, this method will execute immediately and return a value.
If the buffer is empty, this method will block until a value becomes available. The
waiting strategy is a simple spin-wait. If you do not want a spin-wait burning CPU, you
should call try_push()
directly and implement a different waiting strategy.
Examples
let (_, consumer) = make(100); // Block until a value becomes available let t = consumer.pop();
fn try_pop(&self) -> Option<T>
Attempt to pop a value off the queue.
This method does not block. If the queue is empty, the method will return None
. If
there is a value available, the method will return Some(v)
, where v
is the value
being popped off the queue.
Examples
use bounded_spsc_queue::*; let (_, consumer) = make(100); // Attempt to pop a value off the queue let t = consumer.try_pop(); match t { Some(v) => {}, // Successfully popped a value None => {} // Queue empty, try again later }
fn capacity(&self) -> usize
Returns the total capacity of this queue
This value represents the total capacity of the queue when it is full. It does not
represent the current usage. For that, call size()
.
Examples
let (_, consumer) = make(100); assert!(consumer.capacity() == 100); let t = consumer.pop(); assert!(producer.capacity() == 100);
fn size(&self) -> usize
Returns the current size of the queue
This value represents the current size of the queue. This value can be from 0-capacity
inclusive.
Examples
let (_, consumer) = make(100); //... producer pushes somewhere ... assert!(consumer.size() == 10); consumer.pop(); assert!(producer.size() == 9);