clock.rs 820 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //! Example: README.md showcase
  2. //!
  3. //! The example from the README.md.
  4. use dioxus::prelude::*;
  5. use futures_util::Future;
  6. #[tokio::main]
  7. async fn main() {
  8. let mut dom = VirtualDom::new(app);
  9. dom.rebuild();
  10. loop {
  11. dom.wait_for_work().await;
  12. }
  13. // dioxus_desktop::launch(app).await;
  14. }
  15. fn app(cx: Scope) -> Element {
  16. let mut count = use_ref(cx, || 0);
  17. let mut ct = count.to_owned();
  18. use_coroutine(cx, |_: UnboundedReceiver<()>| async move {
  19. loop {
  20. tokio::time::sleep(std::time::Duration::from_millis(10)).await;
  21. *ct.write() += 1;
  22. let current = *ct.read();
  23. println!("current: {}", current);
  24. }
  25. });
  26. let mut count = count.read();
  27. cx.render(rsx! {
  28. div { "High-Five counter: {count}" }
  29. })
  30. }