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]

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();

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
}

Attempts to pop (and discard) at most n values off the buffer.

Returns the amount of values successfully skipped.

Safety

WARNING: This will leak at most n values from the buffer, i.e. the destructors of the objects skipped over will not be called. This function is intended to be used on buffers that contain non-Drop data, such as a Buffer<f32>.

Examples

use bounded_spsc_queue::*;

let (_, consumer) = make(100);

let mut read_position = 0; // current buffer index
read_position += consumer.skip_n(512); // try to skip at most 512 elements

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);

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);

Trait Implementations

impl<T: Send> Send for Consumer<T>
[src]

Auto Trait Implementations

impl<T> !Sync for Consumer<T>