Struct funnel::Funnel [] [src]

pub struct Funnel<T> {
    // some fields omitted
}

Funnel maintains a collection of Receivers which it collects messages from to output to a single source.

Methods

impl<T> Funnel<T>
[src]

fn new() -> Funnel<T>

Creates a new Funnel that received messages of type T with no input sources.

fn push(&mut self, receiver: Receiver<T>)

Adds a new input source to the Funnel, which it takes ownership over.

fn len(&self) -> usize

Obtains the number of input sources that are being read from.

fn remove(&mut self, index: usize) -> Receiver<T>

Removes a specific input source at a given index.

This method is useful in situations where the owner of the Funnel is keeping track of the indexes of Receivers. It is also useful for removing Receivers that can no longer be read from, indicated by any errors returned by a call to recv().

fn add_receiver(&mut self) -> Sender<T>

Creates a new channel, whose Receiver will be managed by the funnel.

fn recv(&mut self) -> (Option<T>, Vec<(RecvError, usize)>)

Attempts to wait for a value on the oldest Receiver not already received from.

Successive calls to recv() result in calls to the recv() method of successive Receivers managed by the funnel. In doing so, channels are read from in an even distribution. As soon as a value is successfully received, it will be returned as the first element of the tuple returned. recv() will accumulate a Vec containing any RecvErrors that may have occurred trying to read from Receivers, as well as the index of those Receivers, allowing users to remove() them if desired.

Examples

use self::funnel::Funnel;
use std::thread;

let mut fun = Funnel::new();
let writer1 = fun.add_receiver();
let writer2 = fun.add_receiver();
thread::spawn(move || {
    let _ = writer1.send(32).unwrap();
});
thread::spawn(move || {
    let _ = writer2.send(64).unwrap();
});
assert!(match fun.recv() {
    (Some(read_value), errors) => read_value == 32 && errors.len() == 0,
    _ => false,
});
assert!(match fun.recv() {
    (Some(read_value), errors) => read_value == 64 && errors.len() == 0,
    _ => false,
});

Trait Implementations

impl<T: Debug> Debug for Funnel<T>
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.