1
0

heavy_compute.rs 675 B

12345678910111213141516171819202122232425262728
  1. //! This example shows that you can place heavy work on the main thread, and then
  2. //!
  3. //! You *should* be using `tokio::spawn_blocking` instead.
  4. //!
  5. //! Your app runs in an async runtime (Tokio), so you should avoid blocking
  6. //! the rendering of the VirtualDom.
  7. //!
  8. //!
  9. use dioxus::prelude::*;
  10. fn main() {
  11. dioxus_desktop::launch(app);
  12. }
  13. fn app(cx: Scope) -> Element {
  14. // This is discouraged
  15. std::thread::sleep(std::time::Duration::from_millis(2_000));
  16. // This is suggested
  17. tokio::task::spawn_blocking(move || {
  18. std::thread::sleep(std::time::Duration::from_millis(2_000));
  19. });
  20. cx.render(rsx! {
  21. div { "Hello, world!" }
  22. })
  23. }