task.rs 772 B

1234567891011121314151617181920212223242526272829303132333435
  1. use std::time::Duration;
  2. use dioxus_core::*;
  3. #[tokio::test]
  4. async fn it_works() {
  5. let mut dom = VirtualDom::new(app);
  6. let _ = dom.rebuild();
  7. tokio::select! {
  8. _ = dom.wait_for_work() => {}
  9. _ = tokio::time::sleep(Duration::from_millis(1000)) => {}
  10. };
  11. }
  12. fn app(cx: Scope) -> Element {
  13. cx.use_hook(|| {
  14. cx.spawn(async {
  15. for x in 0..10 {
  16. tokio::time::sleep(Duration::from_millis(50)).await;
  17. println!("Hello, world! {x}");
  18. }
  19. });
  20. cx.spawn(async {
  21. for x in 0..10 {
  22. tokio::time::sleep(Duration::from_millis(25)).await;
  23. println!("Hello, world from second thread! {x}");
  24. }
  25. });
  26. });
  27. None
  28. }