pub struct ShutdownReceiver { /* private fields */ }Expand description
Listens to shutdown signals and constructs shutdown futures.
Implementations§
Source§impl ShutdownReceiver
impl ShutdownReceiver
Sourcepub fn register<F>(self, future: F) -> AttachedShutdown<F>
pub fn register<F>(self, future: F) -> AttachedShutdown<F>
Create a future which will be cancelled on shutdown.
Examples found in repository?
relm4/examples/drawing.rs (lines 131-136)
114 fn init(
115 _: Self::Init,
116 root: Self::Root,
117 sender: ComponentSender<Self>,
118 ) -> ComponentParts<Self> {
119 let model = App {
120 width: 100.0,
121 height: 100.0,
122 points: Vec::new(),
123 handler: DrawHandler::new(),
124 };
125
126 let area = model.handler.drawing_area();
127 let widgets = view_output!();
128
129 sender.command(|out, shutdown| {
130 shutdown
131 .register(async move {
132 loop {
133 tokio::time::sleep(Duration::from_millis(20)).await;
134 out.send(UpdatePointsMsg).unwrap();
135 }
136 })
137 .drop_on_shutdown()
138 });
139
140 ComponentParts { model, widgets }
141 }More examples
relm4/examples/progress.rs (lines 127-137)
120 fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>, _root: &Self::Root) {
121 match message {
122 Input::Compute => {
123 self.computing = true;
124 sender.command(|out, shutdown| {
125 shutdown
126 // Performs this operation until a shutdown is triggered
127 .register(async move {
128 let mut progress = 0.0;
129
130 while progress < 1.0 {
131 out.send(CmdOut::Progress(progress)).unwrap();
132 progress += 0.1;
133 tokio::time::sleep(std::time::Duration::from_millis(333)).await;
134 }
135
136 out.send(CmdOut::Finished(Ok("42".into()))).unwrap();
137 })
138 // Perform task until a shutdown interrupts it
139 .drop_on_shutdown()
140 // Wrap into a `Pin<Box<Future>>` for return
141 .boxed()
142 });
143 }
144 }
145 }Trait Implementations§
Source§impl Clone for ShutdownReceiver
impl Clone for ShutdownReceiver
Auto Trait Implementations§
impl Freeze for ShutdownReceiver
impl RefUnwindSafe for ShutdownReceiver
impl Send for ShutdownReceiver
impl Sync for ShutdownReceiver
impl Unpin for ShutdownReceiver
impl UnwindSafe for ShutdownReceiver
Blanket Implementations§
Source§impl<C> AsyncPosition<()> for C
impl<C> AsyncPosition<()> for C
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