-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Allowing asynchronous 'stdin' streams via Emterpreter #4124
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
See also #3714 which turned out a little too complicated. Perhaps there is a simpler way. The problem there was the integration deep into libc and syscalls, but if instead we provided Basically, look in |
I see. So if I'm understanding you correctly, something like the following should work:
Where it's up to users (e.g. me) to modify their source programs such that What synchronisation mechanism do you think might be best suited for |
Yes, exactly, something like that. And In other words, |
I've been toying around with some ideas in my local copy of Emscripten and it seems that a system in which suspensions are categorised by identifiers works pretty well. For example, say that
I'm having some problems setting this up to work flawlessly though, probably because I just don't know enough about how Emscripten is structured. I can't figure out how to get Perhaps this would work better if implemented by somebody who actually knows what the heck they're doing - the actual code in |
is |
Yeah, it is - EDIT: Alright, I think I've figured out where default |
How about opening a PR with this? Then we can discuss on the diff, which is usually convenient. |
This issue has been automatically marked as stale because there has been no activity in the past 2 years. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant. |
Though Emscripten allows users to specify custom 'stdin' streams to their
applications through
Module.stdin
, it seems that the value of this issignificantly diminished by its requirement to be synchronous (see: #23, #1849).
A potential solution to this would be to allow for some kind of synchronisation
construct via Emterpreter, such that prior to blocking I/O calls in the source
program, the program waits for a specific signal before continuing. This way,
the compiled JS (which is, say, running in a web worker), can pause until the
main thread signals its readiness to provide an input stream - solving the
fundamental sync/async mismatch in this problem.
I'm not totally sure if this is best implemented in Emscripten itself (such that
the Emterpreter can tell where blocking calls are automatically and perform the
described task if requested), or whether this is something that programs should
implement on their own - either way, any push in the right direction would be
appreciated as I am personally in need of this functionality for my own project.
The text was updated successfully, but these errors were encountered: