Skip to content
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

Disallow blocking_{send,recv} on wasm32 #6159

Closed
wants to merge 2 commits into from

Conversation

frewsxcv
Copy link
Contributor

These current don't work on wasm32 and will panic in runtime

#5548

These current don't work on wasm32 and will panic in runtime

tokio-rs#5548
@github-actions github-actions bot added the R-loom-sync Run loom sync tests on this PR label Nov 19, 2023
@frewsxcv
Copy link
Contributor Author

On second thought, maybe it makes sense to gate this on wasm32-unknown-unknown?

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-sync Module: tokio/sync labels Nov 21, 2023
@Darksonn
Copy link
Contributor

It's not clear to me that there's any reason to disallow these methods. If there's a message available, then they just return it like they should, and otherwise they try to block forever, and wasm currently makes anything that blocks forever panic.

@frewsxcv
Copy link
Contributor Author

@Darksonn One of the main benefits of compiler errors is that unexpected behavior is surfaced to developers immediately rather than waiting for that particular code path is executed during runtime and potentially gets shipped to production. A developer will basically never want to call a function that unconditionally panics, and having it become a compile time error will improve the developer experience.

@Darksonn
Copy link
Contributor

But it doesn't unconditionally panic. It only panics if there's no message.

@frewsxcv
Copy link
Contributor Author

Ah that is a good point. But if you can write your program for WASM in a way that guarantees there is a message, it seems like you shouldn't be using the blocking_* calls anyways.

@Darksonn
Copy link
Contributor

Still, a non-wasm-specific library might use blocking_recv. If we support the method on wasm, then you can use that library in wasm.

And what if you used the library in a case where the recv would block? Well, since wasm has no threads, this means your program would sleep forever, as nobody can ever send another message. Rust wasm has generally made the choice that all APIs that would sleep forever will panic instead, and this is an extension of that.

And if wasm-with-threads gets supported in the future, well, then that would probably include support for condvar, which would make this API start working without changes on our side.

I think, on the balance, the current choice is reasonable.

@Darksonn Darksonn closed this Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-sync Module: tokio/sync R-loom-sync Run loom sync tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants