-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add support for WASM targets #20
Comments
This is interesting to me because I want to use async-channels in a web browser context. I'm willing to help, though I want to understand the issue better.
In a way, this is sort of what already happens with std::sync::Mutex, at least on nightly and with the An annoyance is that std needs to be built with
There is no clean way to detect that parking is not allowed. On web, you can check if you have a Window global context in a hacky way. Alternatively, one can catch a failed wait. WASM does not directly allow that, but you can jump to JS and call I'm not sure this API is very useful, though. How can consuming code recover from an error? Do you have a use case in mind? Maybe it could be a later extension, if the panicking/trapping variant is already useful on its own. Though I might be too hasty, since I'm not familiar with the whole The minimal amount of work that I can see here is not to change anything in this crate, and make the cfg guards on |
In WebAssembly targets, blocking is unimplemented in the standard library except for
target_feature = "atomics"
. Therefore blocking cannot happen until that feature is used. But, we can compile conditionally for that feature.On web browsers, there is an
Atomics
API that can be used to block in Web Workers, but not on the main thread. So we could conditionally select that on web (likegetrandom
does), and then try to get that API. Then, if we're in a web worker, block, and if we're in the main thread, panic.We could even have a
try_park()
method that allows users to handle the case of if they cannot actually park, because they're on the main thread. This would allow users to handle the case of not parking.It would be nice to implement this in
parking
, that way it can be bubbled up to other primitives insmol
.See this comment for more info.
The text was updated successfully, but these errors were encountered: