I'm trying to get a value returned from a C++ function, which calls a JS 
function declared with EM_JS and wrapped with Asyncify.handlerAsync.

The code below reproduces the issue:

// asyncify_return.cpp
#include <string>
#include <iostream>
#include <emscripten.h>
#include <emscripten/bind.h>

EM_JS(void, bar, (), {
  Asyncify.handleAsync(async () => {
    const cache = await caches.open('test123');
    console.log("BAR");
  });
});


int foo()
{
  std::cout << "FOO" << std::endl;
  bar();
  return 42; 
}


EMSCRIPTEN_BINDINGS(File)
{
  emscripten::function("foo", &foo);
}

Then I built it with:
emcc asyncify_return.cpp -o asyncify_return.html --bind -s ASYNCIFY=1 -s 
ASYNCIFY_IMPORTS='["bar"]

Result (executed in Chrome 89.0.4389.82 developer console):

let foo = Module.foo()
FOO
BAR
console.log(foo) // yields 0 instead of 42


I'm wondering why I get 0 instead of 42 here. However, if I comment out 
Asyncify.handleAsync in bar(), everything works fine.

My emcc version:
$ emcc --version
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 
2.0.14 (8dd277d191daee9adfad03e5f0663df2db4b8bb1)

Any help and pointers will be appreciated. Thanks.

-- 
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/b5eedb7d-5ef7-4bf7-aecc-6272bf4c7f2bn%40googlegroups.com.

Reply via email to