2022-11-19 23:24:28 +00:00
|
|
|
//! Verify that tasks get polled by the virtualdom properly, and that we escape wait_for_work safely
|
2022-11-06 08:48:34 +00:00
|
|
|
|
2022-11-23 02:38:27 +00:00
|
|
|
use dioxus::prelude::*;
|
2022-11-19 23:24:28 +00:00
|
|
|
use std::time::Duration;
|
2022-11-06 08:48:34 +00:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn it_works() {
|
|
|
|
let mut dom = VirtualDom::new(app);
|
|
|
|
|
2022-11-12 02:29:27 +00:00
|
|
|
let _ = dom.rebuild();
|
2022-11-06 08:48:34 +00:00
|
|
|
|
2022-11-12 02:29:27 +00:00
|
|
|
tokio::select! {
|
|
|
|
_ = dom.wait_for_work() => {}
|
2022-11-23 02:38:27 +00:00
|
|
|
_ = tokio::time::sleep(Duration::from_millis(600)) => {}
|
2022-11-12 02:29:27 +00:00
|
|
|
};
|
2022-11-06 08:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn app(cx: Scope) -> Element {
|
2022-11-12 02:29:27 +00:00
|
|
|
cx.use_hook(|| {
|
|
|
|
cx.spawn(async {
|
|
|
|
for x in 0..10 {
|
|
|
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
|
|
|
println!("Hello, world! {x}");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
cx.spawn(async {
|
|
|
|
for x in 0..10 {
|
|
|
|
tokio::time::sleep(Duration::from_millis(25)).await;
|
|
|
|
println!("Hello, world from second thread! {x}");
|
|
|
|
}
|
|
|
|
});
|
2022-11-06 08:48:34 +00:00
|
|
|
});
|
|
|
|
|
2022-11-23 02:38:27 +00:00
|
|
|
cx.render(rsx!(()))
|
2022-11-06 08:48:34 +00:00
|
|
|
}
|