pub struct AttachedShutdown<F> { /* private fields */ }Expand description
A future attached to a shutdown receiver.
Implementations§
Source§impl<F, Out> AttachedShutdown<F>where
F: Future<Output = Out>,
impl<F, Out> AttachedShutdown<F>where
F: Future<Output = Out>,
Sourcepub async fn on_shutdown<S>(self, shutdown: S) -> Outwhere
S: Future<Output = Out>,
pub async fn on_shutdown<S>(self, shutdown: S) -> Outwhere
S: Future<Output = Out>,
Creates a future which will resolve to this on shutdown.
Sourcepub async fn wait(self) -> Either<(), Out>
pub async fn wait(self) -> Either<(), Out>
Waits until a shutdown signal is received.
Either::Left(())on cancellation.Either::Right(Out)on registered future completion.
Sourcepub async fn drop_on_shutdown(self)
pub async fn drop_on_shutdown(self)
Waits until a shutdown signal is received.
Ignores any output when we don’t care about it.
Examples found in repository?
relm4/examples/drawing.rs (line 137)
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 (line 139)
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§
Auto Trait Implementations§
impl<F> Freeze for AttachedShutdown<F>where
F: Freeze,
impl<F> RefUnwindSafe for AttachedShutdown<F>where
F: RefUnwindSafe,
impl<F> Send for AttachedShutdown<F>where
F: Send,
impl<F> Sync for AttachedShutdown<F>where
F: Sync,
impl<F> Unpin for AttachedShutdown<F>where
F: Unpin,
impl<F> UnwindSafe for AttachedShutdown<F>where
F: UnwindSafe,
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