pub struct Funnel<D> { /* private fields */ }Expand description
An object that receives data from multiple subscriber and channels the data to a single output.
Using a Funnel object yields the following benefits:
- Consolidates data from multiple sources into a single data stream.
§Example
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
#![feature(unboxed_closures)]
use reflux::Funnel;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use crossbeam_channel::Receiver;
use reflux::add_routine;
use crossbeam_channel::unbounded;
use std::time::Duration;
use std::thread::sleep;
let stop_flag = Arc::new(AtomicBool::new(false));
let stop_flag = Arc::new(AtomicBool::new(false));
let stop_flag = Arc::new(AtomicBool::new(false));
let (mut funnel, funnel_out) = Funnel::new(None, stop_flag.clone(), None);
let (rx1, tx1) = unbounded();
let (rx2, tx2) = unbounded();
let (rx3, tx3) = unbounded();
funnel.add_source(tx1);
funnel.add_source(tx2);
funnel.add_source(tx3);
rx1.send("hello".to_string()).unwrap();
rx2.send("beautiful".to_string()).unwrap();
rx3.send("world".to_string()).unwrap();
let str1 = funnel_out.recv().unwrap();
let str2 = funnel_out.recv().unwrap();
let str3 = funnel_out.recv().unwrap();
assert_eq!(str1, "hello");
assert_eq!(str2, "beautiful");
assert_eq!(str3, "world");
stop_flag.store(true, Ordering::Relaxed);
funnel.join().unwrap()Implementations§
Source§impl<D> Funnel<D>where
D: Send + 'static,
impl<D> Funnel<D>where
D: Send + 'static,
Sourcepub fn new(
pause_sig: Option<Arc<AtomicBool>>,
stop_sig: Arc<AtomicBool>,
data_limit: Option<usize>,
) -> (Self, Receiver<D>)
pub fn new( pause_sig: Option<Arc<AtomicBool>>, stop_sig: Arc<AtomicBool>, data_limit: Option<usize>, ) -> (Self, Receiver<D>)
Sourcepub fn add_source(&mut self, source: Receiver<D>)
pub fn add_source(&mut self, source: Receiver<D>)
Add a data source to the Funnel
§Parameters
source- AReceiverchannel from which data are received
Auto Trait Implementations§
impl<D> Freeze for Funnel<D>
impl<D> !RefUnwindSafe for Funnel<D>
impl<D> Send for Funnel<D>where
D: Send,
impl<D> Sync for Funnel<D>where
D: Send,
impl<D> Unpin for Funnel<D>
impl<D> !UnwindSafe for Funnel<D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more