Timed callbacks for wasm and native


I'm looking for a crate that does what gloo_timers does, and works on both native rust and wasm. Any ideas if something like that exists?
I've had a rough time to find any implementations like that which work in native rust. Most seem to be overly complicated sleep functions.

I mean, this more or less has to be implemented by calling sleep in a new thread. You could make something that waits for many timeouts in one thread, but you can't really run the closures in that thread without rising some closure taking a really long time and making other timeouts not fire in time.

I have OS timers wrapper for both major OSes and wasm

It provides only Future API though
With tokio enabled you can get actually good timers

You can make it callback like by writing custom waker that calls your callback

1 Like

Yeah, looks like I'll have to make two versions. No matter, at least I'll get more practice.

Thank you for the replies.

you're also free to propose callback based api to my crate

I never had time to work on it, because it is hard to make code that allow to re-use for both callback based and future baesd approach.

Though you can also see how simple it is to emulate callback approach with Future https://github.com/DoumanAsh/Jeanne/blob/master/src/config/discord.rs#L61-L71

Mostliky because native timers are callback based, and single poll will cause your waker to waker up without a need for polling