emscripten-core/emscripten

Feature request: MAIN_THREAD_EM_ASYNC_JS

開放

#16,694 建立於 2022年4月11日

 (1 則留言) (0 個反應) (0 位負責人)C++ (3,519 個分叉)batch import
good first bughelp wanted

倉庫指標

星標
 (27,361 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

EM_ASYNC_JS is really useful for writing async JS code with await, however it runs on the thread it was called on. It would be nice if there were a version that proxied the call to the main thread.

The alternative is to use MAIN_THREAD_ASYNC_EM_ASM (extra boilerplate with Asyncify.handleAsync and doesn't define a C function like EM_ASYNC_JS does):

MAIN_THREAD_ASYNC_EM_ASM({
    return Asyncify.handleAsync(async () => {
        // ....
    });
});

and then setting -s 'ASYNCIFY_IMPORTS=["emscripten_receive_on_main_thread_js"]'

related https://github.com/emscripten-core/emscripten/issues/8991#issuecomment-846440750

貢獻者指南