Skip to content

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Dec 23, 2025

This new mode allows the proxied work itself to be asynchronous (i.e.
return a promise). The new behaviour is triggered by marking a
functions as both __proxy: 'sync' and also __async: true.

We can use this new mode to replace the bespoke proxying code that
exists for dlsync as well as the poll system call. For the poll
system call this bespoke code was added in #25523 and #25990, but can
now be completely removed.

In addition to this, because the poll syscall is now marked as
__async it automatically works under JSPI too.

One downside of this new mode is that the proxied work requires the main
thread event loop to run. Unlike the synchronous proxied work that can
complete even when we are deeply nested.

Fixes: #25970

@sbc100 sbc100 changed the title Add new proxying mode for JS library functions Add new async proxying mode for JS library functions Dec 23, 2025
@sbc100 sbc100 requested a review from kripken December 23, 2025 18:53
@sbc100
Copy link
Collaborator Author

sbc100 commented Dec 23, 2025

Still a WIP, especially the name for this new mode..

@sbc100 sbc100 force-pushed the poll_promising branch 3 times, most recently from 4c77b8f to 9ba3164 Compare December 23, 2025 21:43
@sbc100 sbc100 changed the title Add new async proxying mode for JS library functions Allow synchronous proxying of async JS functions Dec 23, 2025
@sbc100
Copy link
Collaborator Author

sbc100 commented Dec 23, 2025

I found that combining __proxy: 'sync' and __async: true works pretty nicely. This also now means that poll() can block on the main thread when JSPI is enabled.

@sbc100 sbc100 requested a review from RReverser December 23, 2025 22:16
sbc100 added a commit to sbc100/emscripten that referenced this pull request Dec 23, 2025
sbc100 added a commit that referenced this pull request Dec 23, 2025
Non-function change split out from #26000.
This new mode allows the proxied work itself to be asynchronous (i.e.
return a promise).  The new behaviour is triggered by marking a
functions as both `__proxy: 'sync'` and also `__async: true`.

We can use this new mode to replace the bespoke proxying code that
exists for `dlsync` as well as the `poll` system call.  For the poll
system call this bespoke code was added in emscripten-core#25523 and emscripten-core#25990, but can
now be completely removed.

In addition to this, because the `poll` syscall is now marked as
`__async` it automatically works under JSPI too.

One downside of this new mode is that the proxied work requires the main
thread event loop to run.  Unlike the synchronous proxied work that can
complete even when we are deeply nested.

Fixes: emscripten-core#25970
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Seamless async integration in JS library code

1 participant