logo
pub struct AsyncRelmWorker<Model, ParentModel> where
    Model: AsyncComponentUpdate<ParentModel, Widgets = ()> + Send + 'static,
    Model::Components: Send,
    ParentModel: ModelTrait,
    ParentModel::Msg: Send,
    Model::Msg: Send
{ /* private fields */ }
This is supported on crate feature tokio-rt only.
Expand description

A AsyncRelmWorker is like a RelmWorker but runs the AsyncComponentUpdate::update function in a tokio Runtime.

Implementations

Create a new AsyncRelmWorker that runs the AsyncComponentUpdate::update function in a tokio Runtime.

Send a message to this component. This can be used by the parent to send messages to this worker.

Examples found in repository
relm4-examples/examples/tokio.rs (line 101)
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
    fn update(&mut self, msg: AppMsg, components: &AppComponents, _sender: Sender<AppMsg>) -> bool {
        self.reset();

        match msg {
            AppMsg::Request(url) => {
                components.http.send(HttpMsg::Request(url)).unwrap();
                self.set_text_waiting(true);
                self.set_image_waiting(true);
            }
            AppMsg::SetText(text_opt) => {
                self.set_text_waiting(false);
                if let Some(text) = text_opt {
                    self.set_text(text);
                } else {
                    self.set_text("No response".to_string());
                }
            }
            AppMsg::SetImage(bytes_opt) => {
                self.set_image_waiting(false);
                if let Some(bytes) = bytes_opt {
                    let buf = Pixbuf::from_read(bytes.reader()).ok();
                    self.set_image_data(buf);
                } else {
                    self.set_image_data(None);
                }
            }
        }
        true
    }

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.