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
Refluxmodules.
§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
impl Outlet
sourcepub fn new<T, F>(outlet_fn: F, stop_sig: Arc<AtomicBool>) -> (Self, Sender<T>)
pub fn new<T, F>(outlet_fn: F, stop_sig: Arc<AtomicBool>) -> (Self, Sender<T>)
Creates a new Outlet object with an unbounded internal channel.
§Parameters
outlet_fn- A function that receives data from aRefluxnetwork and sends it to an external sink.receiver- AReceiverchannel object from which to receive data.stop_sig- A flag to signal theInletobject to terminate
§Returns
- An
Outletobject - A
Senderto send data out to.
sourcepub fn new_bounded<T, F>(
outlet_fn: F,
stop_sig: Arc<AtomicBool>,
data_limit: Option<usize>,
) -> (Self, Sender<T>)
pub fn new_bounded<T, F>( outlet_fn: F, stop_sig: Arc<AtomicBool>, data_limit: Option<usize>, ) -> (Self, Sender<T>)
Creates a new Outlet object, with a bounded internal channel.
§Parameters
outlet_fn- A function that receives data from aRefluxnetwork and sends it to an external sink.receiver- AReceiverchannel object from which to receive data.stop_sig- A flag to signal theInletobject to terminate
§Returns
- An
Outletobject - A
Senderto 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> 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