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?
examples/drawing.rs (lines 131-136)
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
fn init(
_: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = App {
width: 100.0,
height: 100.0,
points: Vec::new(),
handler: DrawHandler::new(),
};
let area = model.handler.drawing_area();
let widgets = view_output!();
sender.command(|out, shutdown| {
shutdown
.register(async move {
loop {
tokio::time::sleep(Duration::from_millis(20)).await;
out.send(UpdatePointsMsg).unwrap();
}
})
.drop_on_shutdown()
});
ComponentParts { model, widgets }
}
More examples
examples/progress.rs (lines 127-137)
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>, _root: &Self::Root) {
match message {
Input::Compute => {
self.computing = true;
sender.command(|out, shutdown| {
shutdown
// Performs this operation until a shutdown is triggered
.register(async move {
let mut progress = 0.0;
while progress < 1.0 {
out.send(CmdOut::Progress(progress)).unwrap();
progress += 0.1;
tokio::time::sleep(std::time::Duration::from_millis(333)).await;
}
out.send(CmdOut::Finished(Ok("42".into()))).unwrap();
})
// Perform task until a shutdown interrupts it
.drop_on_shutdown()
// Wrap into a `Pin<Box<Future>>` for return
.boxed()
});
}
}
}
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