Function relm4::spawn_local

source ·
pub fn spawn_local<F, Out>(func: F) -> JoinHandle<Out>
where F: Future<Output = Out> + 'static, Out: 'static,
Expand description

Spawns a thread-local future on GLib’s executor, for non-Send futures.

Examples found in repository?
examples/typed_list_view_async.rs (lines 93-99)
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
    fn bind(&mut self, widgets: &mut Self::Widgets, _root: &mut Self::Root) {
        println!("Unbind {}", self.value);
        let Widgets {
            label,
            label2,
            button,
        } = widgets;

        let future_binding = self.binding.clone();
        self.handle = Some(relm4::spawn_local(async move {
            loop {
                tokio::time::sleep(Duration::from_secs(1)).await;
                let mut guard = future_binding.guard();
                *guard = guard.wrapping_add(1);
            }
        }));

        label.set_label(&format!("Value: {} ", self.value));
        label2.add_write_only_binding(&self.binding, "label");
        button.set_active(self.value % 2 == 0);
    }