Skip to content
Discussion options

You must be logged in to vote

Yeah, doable. Don't try to make use_server_future re-fire on a schedule, that's not what it's for. Spawn a task that sleeps until the deadline and flips a signal:

let mut expired = use_signal(|| false);

use_future(move || async move {
    let ms = /* deadline - now, in milliseconds */;
    gloo_timers::future::TimeoutFuture::new(ms as u32).await;
    expired.set(true);
});

rsx! {
    if !expired() {
        button { "Sign up" }
    }
}

Why gloo_timers and not tokio::time::sleep: on the web your component runs in wasm, and tokio's timer needs its runtime, which isn't there. TimeoutFuture is backed by the browser's setTimeout, so it just works in the browser.

use_future kicks the timer of…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@madsmh
Comment options

Answer selected by madsmh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants