pub struct Extractor { /* private fields */ }Expand description
Receives data from an external source and sends the data through a channel.
Using an Extractor yields the following benefits:
- Abstracts away the use of channels. You only need to write a coroutine that takes a parameter and yields a result.
- The coroutine does not have to be aware of termination signals, or joining threads. This
functionality is handled by
Extractor. - Easy integration with other
Refluxmodules.
§Example
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
#![feature(unboxed_closures)]
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use crossbeam_channel::Receiver;
use reflux::add_routine;
use reflux::Extractor;
let stop_flag = Arc::new(AtomicBool::new(false));
let (extractor, inlet_chan): (Extractor, Receiver<String>) = Extractor::new(
add_routine!(#[coroutine] |_: ()| {
yield "Hello, world".to_string()
}), stop_flag.clone(), None, (), None);
let data = inlet_chan.recv().unwrap();
stop_flag.store(true, Ordering::Relaxed);
extractor.join().unwrap();
assert_eq!(data, "Hello, world".to_string())Implementations§
Source§impl Extractor
impl Extractor
Sourcepub fn new<F, C, T, I>(
extract_fn: F,
stop_sig: Arc<AtomicBool>,
pause_sig: Option<Arc<AtomicBool>>,
init_data: I,
data_limit: Option<usize>,
) -> (Self, Receiver<T>)
pub fn new<F, C, T, I>( extract_fn: F, stop_sig: Arc<AtomicBool>, pause_sig: Option<Arc<AtomicBool>>, init_data: I, data_limit: Option<usize>, ) -> (Self, Receiver<T>)
Creates a new Extractor object.
§Parameters
extract_fn- A coroutine that reads and returns data from an external source. The use of theadd_routine!macro is necessary when passing in anextract_fn.pause_sig- A flag to signal theExtractorobject to pause execution.stop_sig- A flag to signal theExtractorobject to terminate execution.
§Returns
- A
Extractorobject. - A
Receiverchannel to receive data from theextract_fn.
Auto Trait Implementations§
impl Freeze for Extractor
impl !RefUnwindSafe for Extractor
impl Send for Extractor
impl Sync for Extractor
impl Unpin for Extractor
impl !UnwindSafe for Extractor
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