-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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 EM_ASYNC_JS macro #14728
Add EM_ASYNC_JS macro #14728
Conversation
(I'll add a CHANGELOG entry before merging if everything looks good otherwise) |
Oops, one more fix... |
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
684f05d
to
f7eaee8
Compare
Fixed one more issue - apparently during the introduced Now that's fixed and this PR should be ready to go pending CI & review. |
Adds an easy way to declare asynchronous JS functions. With this helper, users can use `await` directly inside of such snippets, don't need to wrap every such function into `Asyncify.handleAsync` manually, don't need to deal with propagating return values, and, finally, don't need to manually list all such functions in `ASYNCIFY_IMPORTS` since we know statically they're asynchronous. I've also updated docs to merge "returning values" section into the first example, since it's now straightforward with `EM_ASYNC_JS`, a bit more involved but still easy with `EM_JS` + `Asyncify.handleAsync`, and only `Asyncify.handleSleep` API requires more explanation. Fixes #9709.
Co-authored-by: Alon Zakai <[email protected]>
Co-authored-by: Alon Zakai <[email protected]>
If __VA_ARGS__ contains a macro call, compiler would try to expand it before passing to the nested _EM_JS call, causing errors like when `assert(...)` is expanded on the C side instead of being copied literally to JS. To prevent them, stringify __VA_ARGS__ at the top level of each macro.
I've noticed there is a WebGPU test by @austinEng that relies on |
- Added `EM_ASYNC_JS` macro - similar to `EM_JS`, but allows using `await` | ||
inside the JS block and automatically integrates with Asyncify without | ||
the need for listing the declared function in `ASYNCIFY_IMPORTS` (#9709). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changelog note should probably be moved to 2.0.27 (since 2.0.26 was tagged before this PR landed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, was it? At least the release PR came after but I'm not sure about tag itself: https://github.com/emscripten-core/emscripten/commits/main
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, it does look like tag came in earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's so clean, I love it! |
Adds an easy way to declare asynchronous JS functions. With this helper, users can use
await
directly inside of such snippets, don't need to wrap every such function intoAsyncify.handleAsync
manually, don't need to deal with propagating return values, and, finally, don't need to manually list all such functions inASYNCIFY_IMPORTS
since we know statically they're asynchronous.I've also updated docs to merge "returning values" section into the first example, since it's now straightforward with
EM_ASYNC_JS
, a bit more involved but still easy withEM_JS
+Asyncify.handleAsync
, and onlyAsyncify.handleSleep
API requires more explanation.Fixes #9709.