I'm not sure the browsers expose anything to us mere mortals to allow us to 
tick the microtasks.  :(  I can't find anything like process.nextTick() or 
a way to force the Promise I get back from fetch to resolve/execute.

I'd like to get a better understanding of how pthreads work in 
WebAssembly.  I understand they are Web Workers that use SharedArray, but 
won't a Web Worker process its microtasks?  What makes whatever emscripten 
is doing break that?

What's frustrating is that my only option seems to be to rework this using 
synchronous XHR, even though that seems to be discouraged among JavaScript 
developers.  I'm just not sure how else I can make my HTTP requests work 
without blocking the main browser thread.


On Thursday, March 26, 2020 at 1:22:59 AM UTC-7, J Decker wrote:
>
> Not sure if this relates... I had a very similar issue with a node addon, 
> and promises just not resolving.  I'm not sure specifially how your 
> browsers Promises get scheduled, but in V8, the library schedules them as 
> microtasks, that you basically have to call process.tick() in order to kick 
> that event loop.  I don't know if the same functionality exists in the JS 
> browser... 
> You're not supposed to have to worry about such details, but in a thread, 
> if I didn't also call the runmicrotasks sort of thing, the promises 
> resolved never got dispatched.
>
> On Wed, Mar 25, 2020 at 5:52 PM Kevin McGrath wrote:
>
>>   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 
>> USE_PTHREADS=1.
>>
>>   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!
>>
>> -- 
>> 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 [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/emscripten-discuss/1445b398-abcb-483e-8384-6c5bebfc3e29%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/emscripten-discuss/1445b398-abcb-483e-8384-6c5bebfc3e29%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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/5cca4c6d-21d3-48cc-bed5-4b7fd40a334f%40googlegroups.com.

Reply via email to