wip: fragment diffing working

This commit is contained in:
Jonathan Kelley committed 2022-11-23 23:15:01 -08:00
1 parent 0266dfdc05
commit 4dd9a616a5
13 files changed
+489 -258

No files matched your search

+11 -5
View File
@@ -3,6 +3,8 @@
use dioxus::prelude::*;
use std::time::Duration;
static mut POLL_COUNT: usize = 0;
#[tokio::test]
async fn it_works() {
let mut dom = VirtualDom::new(app);
@@ -11,23 +13,27 @@ async fn it_works() {
tokio::select! {
_ = dom.wait_for_work() => {}
_ = tokio::time::sleep(Duration::from_millis(600)) => {}
_ = tokio::time::sleep(Duration::from_millis(10)) => {}
};
// By the time the tasks are finished, we should've accumulated ticks from two tasks
// Be warned that by setting the delay to too short, tokio might not schedule in the tasks
assert_eq!(unsafe { POLL_COUNT }, 135);
}
fn app(cx: Scope) -> Element {
cx.use_hook(|| {
cx.spawn(async {
for x in 0..10 {
tokio::time::sleep(Duration::from_millis(50)).await;
println!("Hello, world! {x}");
tokio::time::sleep(Duration::from_micros(50)).await;
unsafe { POLL_COUNT += x }
}
});
cx.spawn(async {
for x in 0..10 {
tokio::time::sleep(Duration::from_millis(25)).await;
println!("Hello, world from second thread! {x}");
tokio::time::sleep(Duration::from_micros(25)).await;
unsafe { POLL_COUNT += x * 2 }
}
});
});