Skip to content

Commit

Permalink
Prefer use_future.
Browse files Browse the repository at this point in the history
  • Loading branch information
futursolo committed Apr 21, 2022
1 parent 0ccd59e commit f0a452f
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions packages/yew/tests/hydration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use wasm_bindgen_futures::spawn_local;
use wasm_bindgen_test::*;
use web_sys::{HtmlElement, HtmlTextAreaElement};
use yew::prelude::*;
use yew::suspense::{Suspension, SuspensionResult};
use yew::suspense::{use_future, Suspension, SuspensionResult};
use yew::{Renderer, ServerRenderer};

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
Expand Down Expand Up @@ -683,13 +683,8 @@ async fn hydration_list_order_works() {

#[hook]
pub fn use_suspend() -> SuspensionResult<()> {
let s = use_state(|| Suspension::from_future(async {}));

if s.resumed() {
Ok(())
} else {
Err((*s).clone())
}
use_future(|| async {})?;
Ok(())
}

let s = ServerRenderer::<App>::new().render().await;
Expand Down Expand Up @@ -769,17 +764,10 @@ async fn hydration_suspense_no_flickering() {

#[hook]
pub fn use_suspend() -> SuspensionResult<()> {
let s = use_state(|| {
Suspension::from_future(async {
gloo::timers::future::sleep(std::time::Duration::from_millis(50)).await;
})
});

if s.resumed() {
Ok(())
} else {
Err((*s).clone())
}
use_future(|| async {
gloo::timers::future::sleep(std::time::Duration::from_millis(50)).await;
})?;
Ok(())
}

let s = ServerRenderer::<App>::new().render().await;
Expand Down

0 comments on commit f0a452f

Please sign in to comment.