async/async.rs
1use rui::*;
2use std::{
3 thread::{sleep, spawn},
4 time::Duration,
5};
6
7fn main() {
8 rui(state(
9 || "task not started".to_string(),
10 |s, cx| {
11 hstack((
12 button("press to begin", move |_| {
13 spawn(move || {
14 on_main(move |cx| cx[s] = "task started".into());
15 sleep(Duration::from_secs(2));
16 on_main(move |cx| cx[s] = "task complete".into());
17 });
18 }),
19 text(&cx[s]),
20 ))
21 },
22 ));
23}