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

Implement #[wasm_bindgen(start_async)] #3252

Closed
wants to merge 3 commits into from

Conversation

daxpedda
Copy link
Collaborator

@daxpedda daxpedda commented Jan 20, 2023

Adds a new attribute called start_async, it has the exact same behavior as start but rewrites the function to a non-async version that contains the spawn_local inside it.

The purpose is to allow async fn main() to be used in Cargo binaries. It's similar to what #[tokio::main] and others do.

This could have also been done by adjusting start, but the issue is that it might break some behavior, for example one could rely on the function actually being async, which it wouldn't be after the rewrite. This could be mitigated by adjusting the behavior only for functions called main, but it's still a breaking change I would argue.

Fixes #3076.

@daxpedda
Copy link
Collaborator Author

Alternatively we could introduce a new attribute called main, which differs from start in the sense that it is supposed to be used for the fn main() function.
No changes in functionality to start_async, but more descriptive.

@daxpedda
Copy link
Collaborator Author

After some more experimentation I think there should definitely be a new attribute main that is different from start, supposed to only be used with fn main().

The code generation could be much simpler and there are some limitations around exporting main multiple times that could be alleviated this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

async main() support
1 participant