I have an example of JS promises (resolved to a regular callback, so not 
async/await) here in my WIP WebGPU initialization code. It's running on the 
main thread though without blocking though, so I'm not sure if this fits 
into your "application model".

The idea is that the C side calls a JS function which spawns some async 
work and returns immediately to the C side. Then when the async work has 
finished, the JS code calls a C function to pass results back:

https://github.com/floooh/sokol-samples/blob/15359f3075cf6cf07ebae632d1fd121cfd914796/wgpu/wgpu_entry_wasm.c#L29-L54

The JS functions requestAdapter(), requestDevice() and 
getSwapChainPreferredFormat() return a JS promise which is resolved into a 
callback via then().

On Wednesday, 25 March 2020 21:56:34 UTC+1, Kevin McGrath wrote:
>
> Hello!
>
> I'm hoping someone has already run into this before and can tell me what 
> I'm doing wrong...
>
> I have a JavaScript function I'm calling from a C++ multi-threaded game 
> that is designed to perform an async HTTP fetch.
>
> I'm building the game using USE_PTHREADS=1 and PROXY_TO_PTHREAD=1 and I've 
> tried both having the JavaScript function embedded in a EM_JS() and in a 
> --js-library.  The C++ code sparks off a pthread and calls into the 
> JavaScript function, and that JavaScript code executes and then returns 
> back to the C++ code.  What doesn't work is any of the Promise / await 
> code, nothing is executing in those code blocks.
>
> I've tried calling emscripten_thread_sleep() from the C++ code, which is 
> still executing in the thread waiting on the JavaScript asynchronous code 
> to call it back, it just never happens.  The network request is just marked 
> as "(pending)" in Chrome and never changes.
>
> So my question is, what's the right way to run Promise/async/await code in 
> a WebAssembly pthread/Web Worker?
>
> Thank you!!
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/f3ca0057-94db-4140-8b3e-f26b458aef76%40googlegroups.com.

Reply via email to