Replies: 1 comment 16 replies
-
You probably want to take a look the proxying API: https://emscripten.org/docs/api_reference/proxying.h.html And also the C/C++ interface to JS promises: https://github.com/emscripten-core/emscripten/blob/main/system/include/emscripten/promise.h In particular there is an API in promise.h called emscripten/src/library_promise.js Line 12 in b5b7fed @tlively am I missing anything here? |
Beta Was this translation helpful? Give feedback.
-
Hi, I am doing real-time data processing via wasm / c++ and looking to improve efficiency. What I'd like to have happen is this:
Promise
immediately so as not to block the main thread.Promise
object that was returned in step 3.So in JS land, something like:
In c++:
Basically looking for pointers on how to accomplish the above in a correct and hopefully simple way, as there are interactions between JS async, pthreads, and embind class bindings.
Using the c++
future
as written will block the main thread - what's the right pattern to avoid this? I'd like to keep all the thread operations in c++, rather than say creating a separate JS worker and manually passing messages back and forth; and since there is nomain()
here, the-sPROXY_TO_PTHREAD
option isn't viable. Also, for performance reasons I'd like to avoid using asyncify if possible, and for simplicity I'd like to use the c++ standard library (std::thread
,std::future
,std::async
, etc) rather than lower-level pthread or emscripten calls.How can a JS
Promise
object be returned fromprocess_data()
? I've had a look at @RReverser 's c++20 coroutine integration as described here, #20420 which is really interesting and possibly relevant for this use case, but I don't understand it well enough to know how/whether it can work in conjunction with threads.Lastly - how can that
Promise
be resolved after the work is complete, so that the JS promise chain can continue execution?Any help is appreciated. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions