Struct relm4::component::worker::WorkerHandle
source · pub struct WorkerHandle<W: Component> { /* private fields */ }
Expand description
Handle to a worker task in the background
Implementations§
source§impl<W: Component> WorkerHandle<W>where
W::Input: 'static,
W::Output: 'static,
impl<W: Component> WorkerHandle<W>where W::Input: 'static, W::Output: 'static,
sourcepub fn connect_receiver<F: FnMut(&mut Sender<W::Input>, W::Output) + 'static>(
self,
func: F
) -> WorkerController<W>
pub fn connect_receiver<F: FnMut(&mut Sender<W::Input>, W::Output) + 'static>( self, func: F ) -> WorkerController<W>
Given a mutable closure, captures the receiver for handling.
sourcepub fn forward<X: 'static, F: Fn(W::Output) -> X + 'static>(
self,
sender: &Sender<X>,
transform: F
) -> WorkerController<W>
pub fn forward<X: 'static, F: Fn(W::Output) -> X + 'static>( self, sender: &Sender<X>, transform: F ) -> WorkerController<W>
Forwards output events to the designated sender.
Examples found in repository?
relm4/examples/worker.rs (line 97)
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
fn init(
_: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = App {
counter: 0,
worker: AsyncHandler::builder()
.detach_worker(())
.forward(sender.input_sender(), identity),
};
let widgets = view_output!();
ComponentParts { model, widgets }
}
sourcepub fn detach(self) -> WorkerController<W>
pub fn detach(self) -> WorkerController<W>
Ignore outputs from the component and take the handle.