#Live updating/realtime counter

1 messages · Page 1 of 1 (latest)

acoustic snow
#

I have been trying to get anything shared between clients on my website.
For example, a counter that is synced between clients. When 1 client increments it, the other one sees it

This seems imposable because async things are run synchronously on the client (I guess because multi threading is painful on the web).
So I can't even make a polling a server with server functions because it will block everything else.

sacred bridge
#

You’re looking for coroutines which can be async

acoustic snow
#

I will try it, but it is implemented with use_future, and it uses spawn(), which should be async, but isn't 🤷‍♂️

#

Yea, it doesn't work

my code:

    use_coroutine(|rx: UnboundedReceiver<()>| async move {
        loop {
            //
        }
    });

it just freezes when I enter the page

#

this might be the only thing that works, but it has downsides

acoustic snow
#

maybe wasm_bindgen_futures will work?
I will try it, and see

formal idol
#

An alternative to an empty loop is using std::future::pending(), which always gives control back to the runtime

acoustic snow
#

sleep() isn't available in wasm

formal idol
#

Any async .await will do, missed the wasm bit

#

And you can sleep via gloo_timers

acoustic snow
#

seems to work. I will try with gloo_timers

formal idol
#

Perfect 💪

acoustic snow
#

It works! Thanks