-
| 
         Hello everyone // can't actually be run from multiple threads at the same time - dangerous
MAIN_THREAD_EM_ASM({
    return Asyncify.handleAsync(async () => {
        await someAsyncOperationThatMustRunFromMainThread();
    });
});The problem is that if two operations happen simultanously then Asyncify goes shenaneganes (it has a state for rewind which is ruined) I believe this is the section in the docs that speaks about this problem Thanks  | 
  
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
Beta Was this translation helpful? Give feedback.
-
| 
         @tlively what do you think about creating a variant of   | 
  
Beta Was this translation helpful? Give feedback.
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 useproxying.h[https://emscripten.org/docs/api_reference/proxying.h.html] to set up the proxying to the main thread yourself. Specifically, you should use theemscripten_proxy_sync_with_ctxorProxyingQueue::proxySyncWithCtxfunctions to proxy the work to the main thread, where you should call into the async JS without asyncify and arrange it so that you callemscripten_proxy_finishwhen 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.