-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enabling time causes panic on wasm32-unknown-unknown
target
#5418
Comments
I don't know how much we can do about this. Our wasm support is pretty limited, and we only support timers when you're using a wasm platform that supports them. I guess we could catch the panic so that we do not fail until someone tries to actually use a timer. |
same problem here, tokio Instant depends std Instant which is not available in |
Tokio does not require a timer. If you're on a platform that doesn't support timers, then you shouldn't enable the time feature of Tokio. |
Shouldn't it error at compile time to prevent it from even compiling instead of having an error at runtime? |
I also have issues with this, since using |
I think we can refer to the idea from this repo: https://github.com/tomaka/wasm-timer But the thing is, are we allowed to make pull requests that use some JavaScript crates, such as |
Tokio isn't going to support that at this time. Making the runtime usable in wasm environments where you're expected to yield out of wasm would require a completely separate runtime implementation from what Tokio does today. |
Yeah, I'm aware of the fact that in many cases, we yield out of wasm to go back to Javascript world. However, there are also cases where tokio runtime is occupying a web worker with its own business logic(without yielding), which means tokio running in wasm does has its uses. Actually, without the feature IMHO providing basic support for wasm, including |
To my knowledge, it is not possible to support timers in a web worker without yielding entirely out of wasm when sleeping. |
Closing as working-as-intended. We do not currently have any support for wasm platforms where we cannot block. We may add that feature in the future (and you could file a feature request for that), but this issue is a bug, and the fact that we don't have a specific feature is not a bug. |
Version
tokio v1.25.0
Platform
Linux 5.10.161-1-MANJARO x86_64
Chromium Version 109.0.5414.74 (Official Build) Arch Linux (64-bit)
Description
I've been trying to implement a platform-independent asynchronous game loop with a fixed amount of time between each game tick for an NES emulator with
tokio
.Enabling the
time
feature and building a simple application like the following causes the program to panic:The panic's trace as can be found in my browser's console is the following:
I'm using
cargo run-wasm
(https://github.com/rukai/cargo-run-wasm) to get the program running.I'm not sure if I should flag this issue as a bug or a feature request; it seems like Wasm support hasn't been implemented for the
time
feature yet, but I haven't been able to find any issues tracking this situation's status.Taking a quick look at the panic trace, I think the bug comes from the usage of
std::time::Instant::now
, which apparently panics on Wasm platforms. Something like https://github.com/sebcrozet/instant could be used to fix this, although it doesn't seem to be actively mantained.I'm a beginner in
tokio
, but I could try to help solve the issue in case it's not too complicated.Thanks!
The text was updated successfully, but these errors were encountered: