reflux

Struct Funnel

Source
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,

Source

pub fn new( pause_sig: Option<Arc<AtomicBool>>, stop_sig: Arc<AtomicBool>, data_limit: Option<usize>, ) -> (Self, Receiver<D>)

Creates a new Funnel object

§Parameters
  • pause_sig - A flag to signal the Funnel object to pause execution.
  • stop_sig - A flag to signal the Funnel object to terminate execution.
§Returns
  • A Funnel object.
  • A Receiver channel for Funnel output.
Source

pub fn add_source(&mut self, source: Receiver<D>)

Add a data source to the Funnel

§Parameters
  • source - A Receiver channel from which data are received
Source

pub fn join(self) -> Result<()>

Waits for the Funnel object to finish execution

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.