only poll suspended futures
This commit is contained in:
1 parent
608fec59e5
commit
c9603ea984
7 files changed
+140
-46
No files matched your search
@@ -1,9 +1,10 @@
|
||||
use dioxus::prelude::*;
|
||||
use std::future::poll_fn;
|
||||
use std::task::Poll;
|
||||
|
||||
#[test]
|
||||
fn suspense_resolves() {
|
||||
// wait just a moment, not enough time for the boundary to resolve
|
||||
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.build()
|
||||
.unwrap()
|
||||
@@ -31,11 +32,35 @@ fn app() -> Element {
|
||||
fn suspended_child() -> Element {
|
||||
let mut val = use_signal(|| 0);
|
||||
|
||||
// Tasks that are not suspended should never be polled
|
||||
spawn(async move {
|
||||
panic!("Non-suspended task was polled");
|
||||
});
|
||||
|
||||
// // Memos should still work like normal
|
||||
// let memo = use_memo(move || val * 2);
|
||||
// assert_eq!(memo, val * 2);
|
||||
|
||||
if val() < 3 {
|
||||
spawn(async move {
|
||||
let task = spawn(async move {
|
||||
// Poll each task 3 times
|
||||
let mut count = 0;
|
||||
poll_fn(|cx| {
|
||||
println!("polling... {}", count);
|
||||
if count < 3 {
|
||||
count += 1;
|
||||
cx.waker().wake_by_ref();
|
||||
Poll::Pending
|
||||
} else {
|
||||
Poll::Ready(())
|
||||
}
|
||||
})
|
||||
.await;
|
||||
|
||||
println!("waiting... {}", val);
|
||||
val += 1;
|
||||
});
|
||||
suspend()?;
|
||||
suspend(task)?;
|
||||
}
|
||||
|
||||
rsx!("child")
|
||||
|
||||
Reference in new issue
Block a user