emscripten-core / emscripten-core/emscripten

Feature request: MAIN_THREAD_EM_ASYNC_JS

Open
#16,694 1 comment 0 reactions 0 assignees View on GitHub
good first bug help wanted
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

`EM_ASYNC_JS` is really useful for writing async JS code with `await`, however it runs on the thread it was called on. It would be nice if there were a version that proxied the call to the main thread.

The alternative is to use `MAIN_THREAD_ASYNC_EM_ASM` (extra boilerplate with `Asyncify.handleAsync` and doesn't define a C function like `EM_ASYNC_JS` does):

```
MAIN_THREAD_ASYNC_EM_ASM({
return Asyncify.handleAsync(async () => {
// ....
});
});
```

and then setting `-s 'ASYNCIFY_IMPORTS=["emscripten_receive_on_main_thread_js"]'`

related https://github.com/emscripten-core/emscripten/issues/8991#issuecomment-846440750

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.