Ah!  Thanks for the details!  I looked into Asyncify and ruled it out 
because of this from the emscripten documentation:

It is not safe to start an async operation while another is already 
> running. The first must complete before the second begins.

  That would mean one HTTP request at a time, one after another, and any 
time we want to use Asyncify for any other async JavaScript tasks we may 
run into trouble that would be a nightmare to debug.  Plus there's more 
issues described in that doc, such as if we get an event (like a keypress) 
while the async JavaScript is running it doesn't sound too stable when it 
calls into compiled code.  Lastly, they mention that you should always run 
optimized builds if you're using Asyncify, which will not be fun to debug.  
Taking all of that into consideration, it didn't sound like a good option 
to me, especially since I wasn't sure it would work in the first place with 

  I'm not sure I understand how emscripten_set_main_loop() will help my 
JavaScript execute the async code... are you saying that the compiled code 
in each thread is blocking the JavaScript code?

  Sorry for so many questions, I'm very new to JavaScript and know very 
little about its internal workings.  Also seems impossible to Google for 
this kind of stuff.

  Thank you!

On Wednesday, March 25, 2020 at 4:39:29 PM UTC-7, Alon Zakai wrote:
> emscripten_thread_sleep() will check the pthread event queue, which means 
> it can receive C messages from other threads - those are synchronized using 
> shared memory. However, it can't help with JS events, as to get those to 
> happen you need to actually return to the main JS event loop. The browser 
> won't run those events otherwise.
> To do that, you can use Asyncify (
> https://emscripten.org/docs/porting/asyncify.html) and 
> emscripten_sleep(). Or, you can manually return to the main event loop 
> yourself, replacing an infinite event loop with an 
> emscripten_set_main_loop() etc.
> On Wed, Mar 25, 2020 at 1:56 PM Kevin McGrath <kevin....@catdaddy.com 
> <javascript:>> 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 <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/emscripten-discuss/aecd43c5-6662-4d7d-bb8c-15461e75522e%40googlegroups.com
>> <https://groups.google.com/d/msgid/emscripten-discuss/aecd43c5-6662-4d7d-bb8c-15461e75522e%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .

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 

Reply via email to