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
Refluxmodules.
§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
impl Loader
Sourcepub fn new<T, F>(
loader_fn: F,
pause_sig: Option<Arc<AtomicBool>>,
stop_sig: Arc<AtomicBool>,
data_limit: Option<usize>,
) -> (Self, Sender<T>)
pub fn new<T, F>( loader_fn: F, pause_sig: Option<Arc<AtomicBool>>, stop_sig: Arc<AtomicBool>, data_limit: Option<usize>, ) -> (Self, Sender<T>)
Creates a new Loader object.
§Parameters
loader_fn- A function that receives data from aRefluxnetwork and sends it to an external sink.receiver- AReceiverchannel object from which to receive data.pause_sig- A flag to signal theLoaderobject to pause execution.stop_sig- A flag to signal theLoaderobject to terminate execution.
§Returns
- A
Loaderobject. - A
Senderchannel to send data out to.
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> 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