ShutdownReceiver

Struct ShutdownReceiver 

Source
pub struct ShutdownReceiver { /* private fields */ }
Expand description

Listens to shutdown signals and constructs shutdown futures.

Implementations§

Source§

impl ShutdownReceiver

Source

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
Hide additional 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    }
Source

pub async fn wait(self)

Waits until a shutdown signal is received.

Trait Implementations§

Source§

impl Clone for ShutdownReceiver

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ShutdownReceiver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<C> AsyncPosition<()> for C

Source§

fn position(_index: usize)

Returns the position. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<C, I> Position<(), I> for C

Source§

fn position(&self, _index: &I)

Returns the position. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more