2022-02-19 22:34:44 +00:00
|
|
|
//! This example shows that you can place heavy work on the main thread, and then
|
|
|
|
//!
|
|
|
|
//! You *should* be using `tokio::spawn_blocking` instead.
|
|
|
|
//!
|
|
|
|
//! Your app runs in an async runtime (Tokio), so you should avoid blocking
|
|
|
|
//! the rendering of the VirtualDom.
|
|
|
|
//!
|
|
|
|
//!
|
|
|
|
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
2022-07-09 19:15:20 +00:00
|
|
|
dioxus_desktop::launch(app);
|
2022-02-19 22:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
// This is discouraged
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(2_000));
|
|
|
|
|
|
|
|
// This is suggested
|
|
|
|
tokio::task::spawn_blocking(move || {
|
|
|
|
std::thread::sleep(std::time::Duration::from_millis(2_000));
|
|
|
|
});
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div { "Hello, world!" }
|
|
|
|
})
|
|
|
|
}
|