Sending a signal at a specific time and date #5486
|
I am working on a webapp that will let users sign up for meals, but there is a deadline to sign up for each meal. I would like to be able to send a signal when that deadline passes to hide the sign up/cancel buttons without the user having to reload the page. Is this possible? Are there alternative approaches? I have been trying to find out how to update a |
Replies: 1 comment 1 reply
|
Yeah, doable. Don't try to make 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
Two things to watch:
|
Yeah, doable. Don't try to make
use_server_futurere-fire on a schedule, that's not what it's for. Spawn a task that sleeps until the deadline and flips a signal:Why
gloo_timersand nottokio::time::sleep: on the web your component runs in wasm, and tokio's timer needs its runtime, which isn't there.TimeoutFutureis backed by the browser'ssetTimeout, so it just works in the browser.use_futurekicks the timer of…