Function clocked_dispatch::fuse [] [src]

pub fn fuse<T: Clone + Send + 'static>(sources: Vec<ClockedReceiver<T>>, bound: usize) -> ClockedReceiver<T>

Fuses together the output streams of multiple clocked receivers into another clocked stream.

This lets you wait for updates from many different senders, maintaining the guarantees of in-order, clocked delivery. Once all receivers managed by the fuse are up to date to some sequence number x, all messages with sequence number <= x will be delivered by the fuse output in order of their sequence numbers.

Examples

Simple usage:

use clocked_dispatch;

let d = clocked_dispatch::new(10);
let (tx1, rx1) = d.new("tx1", "rx1");
let (tx2, rx2) = d.new("tx2", "rx2");

let fused = clocked_dispatch::fuse(vec![rx1, rx2], 10);

tx1.send("1");
let rx1 = fused.recv().unwrap();

tx2.send("2");
let rx2 = fused.recv().unwrap();

assert_eq!(rx1.0, Some("1"));
assert_eq!(rx2.0, Some("2"));
assert!(rx2.1 > rx1.1);

Clocked delivery:

use clocked_dispatch;

let d = clocked_dispatch::new(10);
let (tx1, rx1) = d.new("tx1", "rx1");
let (_, rx2) = d.new("tx2", "rx2");
let (tx3, _) = d.new("tx3", "rx3");

// notice that rx3 is *not* fused
let fused = clocked_dispatch::fuse(vec![rx1, rx2], 10);

tx3.send("3");
assert_eq!(fused.recv().unwrap().0, None);

tx1.send("1");
assert_eq!(fused.recv().unwrap().0, Some("1"));