emscripten-core / emscripten-core/emscripten
Emscripten fetch API won't invoke callback if the calling thread is in waiting.
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
We ran into an issue with Emscripten fetch API in ASYNC mode.
After a thread issued a Emscripten fetch call, we put it in waiting status, meaning we call std::conditional_variable::wait() on the calling thread. In this case, the fetch callbacks never get invoked.
The structure of our code is something like:
- function definition:
```
void invokeNetworkingCall(callback){
_attr.onsuccess = callback;
emscripten_fetch(_attr, ...);
}
```
/////////////////////////////////////////////
- In the calling thread:
```
std::conditional_variable c;
invokeNetworkingCall([&c]{
// some operations
c.notify_all();
});
c.wait();
```
I've read the documentation about the "Waitable" mode, but not sure if that's related to this issue. But anyway, I wonder what's the reason this happens, even I've pass the -pthread + -s PROXY_TO_PTHREAD to the compiler/linker, which enable pthread and ran app on it. Shouldn't the callback of "Fetch API" triggered from a different thread than the calling one?
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.