@@ -402,7 +402,7 @@ int emscripten_proxy_sync_with_ctx(em_proxying_queue* q,
402402 return ret ;
403403}
404404
405- int emscripten_proxy_promise_await_with_ctx (em_proxying_queue * q ,
405+ int emscripten_proxy_async_await_with_ctx (em_proxying_queue * q ,
406406 pthread_t target_thread ,
407407 void (* func )(em_proxying_ctx * , void * ),
408408 void * arg , proxied_js_func_t * f ) {
@@ -446,12 +446,12 @@ int emscripten_proxy_sync(em_proxying_queue* q,
446446 q , target_thread , call_then_finish_task , & t );
447447}
448448
449- int emscripten_proxy_promise_await (em_proxying_queue * q ,
449+ int emscripten_proxy_async_await (em_proxying_queue * q ,
450450 pthread_t target_thread ,
451451 void (* func )(void * ),
452452 proxied_js_func_t * f ) {
453453 task t = {.func = func , .arg = (void * )f };
454- return emscripten_proxy_promise_await_with_ctx (
454+ return emscripten_proxy_async_await_with_ctx (
455455 q , target_thread , call_task , & t , f );
456456}
457457
@@ -642,25 +642,18 @@ static void run_js_func(void* arg) {
642642 }
643643}
644644
645- static void run_js_promise_await (void * arg ) {
645+ static void run_js_async_await (void * arg ) {
646646 proxied_js_func_t * f = (proxied_js_func_t * )arg ;
647647 f -> result = _emscripten_receive_on_main_thread_js (
648648 f -> funcIndex , f -> emAsmAddr , f -> callingThread , f -> numArgs , f -> argBuffer , (void * )f -> ctx );
649649}
650650
651- void _emscripten_proxy_promise_finish (void * res , em_proxying_ctx * ctx ) {
652- task * t = (task * )ctx -> arg ;
653- proxied_js_func_t * func = (proxied_js_func_t * )t -> arg ;
654- func -> result = (double )(intptr_t )res ;
655- emscripten_proxy_finish (ctx );
656- }
657-
658651double _emscripten_run_on_main_thread_js (int func_index ,
659652 void * em_asm_addr ,
660653 int num_args ,
661654 double * buffer ,
662655 int sync ,
663- int promise ) {
656+ int asyncAwait ) {
664657 proxied_js_func_t f = {
665658 .funcIndex = func_index ,
666659 .emAsmAddr = em_asm_addr ,
@@ -673,18 +666,19 @@ double _emscripten_run_on_main_thread_js(int func_index,
673666 em_proxying_queue * q = emscripten_proxy_get_system_queue ();
674667 pthread_t target = emscripten_main_runtime_thread_id ();
675668
676- if (sync && !promise ) {
677- if (!emscripten_proxy_sync (q , target , run_js_func , & f )) {
669+ // make sure it is not the case that sync==false and asyncAwait==true
670+ assert (!(sync == 0 && asyncAwait == 1 ) && "asyncAwait cannot be true if sync is false" );
671+ if (sync ) {
672+ if (asyncAwait ) {
673+ if (!emscripten_proxy_async_await (q , target , run_js_async_await , & f )) {
674+ assert (false && "emscripten_proxy_promise failed" );
675+ return 0 ;
676+ }
677+ } else if (!emscripten_proxy_sync (q , target , run_js_func , & f )) {
678678 assert (false && "emscripten_proxy_sync failed" );
679679 return 0 ;
680680 }
681681 return f .result ;
682- } else if (sync && promise ) {
683- if (!emscripten_proxy_promise_await (q , target , run_js_promise_await , & f )) {
684- assert (false && "emscripten_proxy_promise failed" );
685- return 0 ;
686- }
687- return f .result ;
688682 }
689683
690684 // Make a heap-heap allocated copy of the proxied_js_func_t
@@ -701,3 +695,10 @@ double _emscripten_run_on_main_thread_js(int func_index,
701695 }
702696 return 0 ;
703697}
698+
699+ void _emscripten_proxy_promise_finish (em_proxying_ctx * ctx , void * res ) {
700+ task * t = (task * )ctx -> arg ;
701+ proxied_js_func_t * func = (proxied_js_func_t * )t -> arg ;
702+ func -> result = (double )(intptr_t )res ;
703+ emscripten_proxy_finish (ctx );
704+ }
0 commit comments