reflux

Struct Loader

Source
pub struct Loader { /* private fields */ }
Expand description

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

Using an Loader 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 Loader.
  • Easy integration with other Reflux modules.

§Example

 use reflux::Loader;
 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 (loader, out_send)= Loader::new(move |test: String| {
     test_tx.send(test).unwrap();
 }, None, stop_flag.clone(), None);
 
 out_send.send("Hello, world".to_string()).unwrap();
 
 let data_recv = test_rx.recv().unwrap();
 stop_flag.store(true, Ordering::Relaxed);
 loader.join().unwrap();
 
 assert_eq!(data_recv, "Hello, world".to_string())

Implementations§

Source§

impl Loader

Source

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

Creates a new Loader object.

§Parameters
  • loader_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.
  • pause_sig - A flag to signal the Loader object to pause execution.
  • stop_sig - A flag to signal the Loader object to terminate execution.
§Returns
  • A Loader object.
  • A Sender channel to send data out to.
Source

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

Waits for the Loader object to finish execution.

Auto Trait Implementations§

§

impl Freeze for Loader

§

impl !RefUnwindSafe for Loader

§

impl Send for Loader

§

impl Sync for Loader

§

impl Unpin for Loader

§

impl !UnwindSafe for Loader

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.