Struct reflux::Outlet

source ·
pub struct Outlet { /* private fields */ }
Expand description

An object that receives data from a Reflux network and sends the data to some external sink.

Using an Outlet yields the following benefits:

  • Abstracts away the use of channels. You only need to receive a parameter and send it to an external sink
  • The function does not have to be aware of termination signals, or joining threads. This functionality is handled by Outlet.
  • Easy integration with other Reflux modules.

§Example

 use reflux::Outlet;
 use std::sync::Arc;
 use std::sync::atomic::{AtomicBool, Ordering};
 use crossbeam_channel::Receiver;
 use reflux::add_routine;
 use crossbeam_channel::unbounded;
 use std::thread::sleep;
 
 let stop_flag = Arc::new(AtomicBool::new(false));
 let (test_tx, test_rx) = unbounded();
 let (outlet, out_send)= Outlet::new(move |test: String| {
     test_tx.send(test).unwrap();
 }, stop_flag.clone());
 
 out_send.send("Hello, world".to_string()).unwrap();
 
 let data_recv = test_rx.recv().unwrap();
 stop_flag.store(true, Ordering::Relaxed);
 outlet.join().unwrap();
 
 assert_eq!(data_recv, "Hello, world".to_string())

Implementations§

source§

impl Outlet

source

pub fn new<T, F>(outlet_fn: F, stop_sig: Arc<AtomicBool>) -> (Self, Sender<T>)
where T: Send + 'static, F: FnMut(T) + Send + 'static,

Creates a new Outlet object with an unbounded internal channel.

§Parameters
  • outlet_fn - A function that receives data from a Reflux network and sends it to an external sink.
  • receiver - A Receiver channel object from which to receive data.
  • stop_sig - A flag to signal the Inlet object to terminate
§Returns
  • An Outlet object
  • A Sender to send data out to.
source

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

Waits for the Outlet object to finish execution

source

pub fn new_bounded<T, F>( outlet_fn: F, stop_sig: Arc<AtomicBool>, data_limit: Option<usize>, ) -> (Self, Sender<T>)
where T: Send + 'static, F: FnMut(T) + Send + 'static,

Creates a new Outlet object, with a bounded internal channel.

§Parameters
  • outlet_fn - A function that receives data from a Reflux network and sends it to an external sink.
  • receiver - A Receiver channel object from which to receive data.
  • stop_sig - A flag to signal the Inlet object to terminate
§Returns
  • An Outlet object
  • A Sender to send data out to.

Auto Trait Implementations§

§

impl Freeze for Outlet

§

impl !RefUnwindSafe for Outlet

§

impl Send for Outlet

§

impl Sync for Outlet

§

impl Unpin for Outlet

§

impl !UnwindSafe for Outlet

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.