task.rs 873 B

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