You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there is a perceived inconsistency between APIs like emscripten_sleep and emscripten_fetch: while both perform sort of an async I/O, one of them works with Asyncify, while another works only by compiling code in a separate thread.
Technically, there is no reason for this discrepancy, and it should be possible to allow APIs like emscripten_fetch with just Asyncify if user wants it to run on the main thread instead of a separate one.
Perhaps this is a more general issue though and there should be some shared mechanism for all such APIs to choose between Asyncify and thread-based blocking depending on compile flags?
I agree it would be better to support all APIs with Asyncify. It does take a little manual work for each which is why that's not the case yet.
Also no one is actively working on Fetch atm. @juj has plans to create something lower-level and better. We can add Asyncify support more easily for that API, I expect.
We already have emscripten_wget and emscripten_fetch, where both do sorts of network requests, but cover different use-cases, and one works only with Asyncify and another only with proxy-to-thread.
I think ideally we should still consolidate existing APIs to work under either of those modes, regardless of future additions.
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.
We should probably asyncify emscripten_thread_sleep too, and perhaps merge it with emscripten_sleep (there should be no need for both of those functions I think).
Just need to be careful with various conditions: off the main thread emscripten_thread_sleep is more efficient as it just uses atomic.wait; on the main thread emscripten_sleep is better than busy-loop, but only works when user opted in to Asyncify + when used implicitly, can have some surprising effects due to exports becoming async too now.
Probably expressed myself in a bit confusing manner, so just to clarify: yes, I certainly agree it would be great for emscripten_thread_sleep / usleep / etc. to use Asyncify, just need to make sure we use it only 1) on the main thread and 2) if the user explicitly opted in to Asyncify.
Perhaps this is a more general issue though and there should be some shared mechanism for all such APIs to choose between Asyncify and thread-based blocking depending on compile flags?
It would be cool to solve this problem once for all APIs to avoid repeating complexity. So that there would be a single internal API which you could ask to do something asynchronous, and it would choose a mechanism between Asyncify / pthread / block on the same thread based on user-provided flags.
sleep and fetch seem like excellent examples to cover first for a PoC.
Activity
kripken commentedon Sep 17, 2020
I agree it would be better to support all APIs with Asyncify. It does take a little manual work for each which is why that's not the case yet.
Also no one is actively working on Fetch atm. @juj has plans to create something lower-level and better. We can add Asyncify support more easily for that API, I expect.
RReverser commentedon Sep 19, 2020
I'm a bit worried about this getting into https://xkcd.com/927/ territory, where we simply will end up with 3 APIs that work in different modes :)
We already have
emscripten_wgetandemscripten_fetch, where both do sorts of network requests, but cover different use-cases, and one works only with Asyncify and another only with proxy-to-thread.I think ideally we should still consolidate existing APIs to work under either of those modes, regardless of future additions.
stale commentedon Jul 31, 2022
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.
sbc100 commentedon Nov 28, 2022
We should probably asyncify emscripten_thread_sleep too, and perhaps merge it with emscripten_sleep (there should be no need for both of those functions I think).
RReverser commentedon Nov 28, 2022
Just need to be careful with various conditions: off the main thread emscripten_thread_sleep is more efficient as it just uses atomic.wait; on the main thread emscripten_sleep is better than busy-loop, but only works when user opted in to Asyncify + when used implicitly, can have some surprising effects due to exports becoming async too now.
RReverser commentedon Nov 28, 2022
Probably expressed myself in a bit confusing manner, so just to clarify: yes, I certainly agree it would be great for emscripten_thread_sleep / usleep / etc. to use Asyncify, just need to make sure we use it only 1) on the main thread and 2) if the user explicitly opted in to Asyncify.
sbc100 commentedon Nov 28, 2022
Yup, thanks for extra details there.. certainly seems more complex than I originally though.
RReverser commentedon Nov 29, 2022
Heh yeah which brings me back to
It would be cool to solve this problem once for all APIs to avoid repeating complexity. So that there would be a single internal API which you could ask to do something asynchronous, and it would choose a mechanism between Asyncify / pthread / block on the same thread based on user-provided flags.
sleep and fetch seem like excellent examples to cover first for a PoC.