JSPI/Asyncify - how to call from JavaScript #19440
-
Let's say I have this cpp file: #include <emscripten/bind.h>
#include <emscripten/val.h>
#include <emscripten.h>
// em++ --bind -O3 repro.cpp -o repro.html -s ASYNCIFY=2
using namespace emscripten;
EM_ASYNC_JS(int, run, (), {
return Promise.resolve(42);
});
int cppRun() {
return run();
};
EMSCRIPTEN_BINDINGS() {
emscripten::function("run", &run);
emscripten::function("cppRun", &cppRun);
}
EMSCRIPTEN_KEEPALIVE int main() {
printf("start\n");
printf("Out %d\n", cppRun());
printf("end\n");
return 0;
} During startup (ie calling
Now however if I call it using
What's weird is that if I compile with Asyncify=1 it works. Any idea why? Is this supported at all? I would expect cppRun() to return a JS promise. |
Beta Was this translation helpful? Give feedback.
Answered by
brendandahl
May 24, 2023
Replies: 1 comment
-
Since the binding cpprun can suspend you need to mark it as async: emscripten::function("cppRun", &cppRun, emscripten::async()); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
isaackwan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since the binding cpprun can suspend you need to mark it as async: