Skip to content

Question: What is the correct way to call asynchronous APIs on main thread from pthreads #21929

Answered by tlively
hedwigz asked this question in Q&A
Discussion options

You must be logged in to vote

I would avoid using Asyncify at all since no Wasm code needs to be suspended to make this work.

Instead of using MAIN_THREAD_EM_ASM, I would use proxying.h[https://emscripten.org/docs/api_reference/proxying.h.html] to set up the proxying to the main thread yourself. Specifically, you should use the emscripten_proxy_sync_with_ctx or ProxyingQueue::proxySyncWithCtx functions to proxy the work to the main thread, where you should call into the async JS without asyncify and arrange it so that you call emscripten_proxy_finish when the async work is done.

As an example, you can see how this code proxies work to another thread, where it is executed asyncronously in JS.

Replies: 2 comments 11 replies

Comment options

You must be logged in to vote
5 replies
@tlively
Comment options

Answer selected by hedwigz
@hedwigz
Comment options

@hedwigz
Comment options

@tlively
Comment options

@hedwigz
Comment options

Comment options

You must be logged in to vote
6 replies
@hedwigz
Comment options

@sbc100
Comment options

@hedwigz
Comment options

@sbc100
Comment options

@hedwigz
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants