emscripten-core / emscripten-core/emscripten

Emscripten fetch API won't invoke callback if the calling thread is in waiting.

Open
#13,752 11 comments 0 reactions 0 assignees View on GitHub
wontfix
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.