Repository navigation
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. |
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.
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.
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.
Oh, I see, it does look like tag came in earlier.
|
It's so clean, I love it! |
Adds an easy way to declare asynchronous JS functions. With this helper, users can use
awaitdirectly inside of such snippets, don't need to wrap every such function intoAsyncify.handleAsyncmanually, don't need to deal with propagating return values, and, finally, don't need to manually list all such functions inASYNCIFY_IMPORTSsince 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.handleSleepAPI requires more explanation.Fixes #9709.