-
Notifications
You must be signed in to change notification settings - Fork 3.5k
wip make select() async when using ASYNCIFY/JSPI #25981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Nice idea! Its interesting that we just added potential for select to block in #25523, but I assume you two are working independently? I have some ideas knocking around about how I think this stuff could be made to be blocking also when called from threads: #25970 I'd also like to refactor such that this version of select can be deleted and we can implement just poll instead (because select can be implemented in native code in terms of poll). But I like this idea! |
|
Does the preprocessor support some way to conditionally add the async keyword in front of a function? For example, could I do like - and also then Where these are empty when ASYNCIFY is disabled? That would at least make the #if ASYNCIFY stuff a bit nicer, but it wouldn't ensure that the __async decorator is set still. |
|
Yes, we already have something like that. See |
Is there anything also dealing with the decorator? I was trying to think if there was some way to generate a structure and abuse the spread operator to make that auto-magic. The idea being to end up pasting something like - but doing that by pasting in something up front would require the rogue extra } at the end. Can the preprocessor take in a JS function body as an argument somehow? |
|
See the existing uses of |
Right, that's what I was trying to noodle to see if it was possible to improve. That's effectively what I'm doing here, but I was trying to think if there was a better way to do that such that both the decorator and async prefix were emitted as a result. For example, I wonder if it's possible to do like - and that emit out |
Absolutely, I think we would be great if we could have single approach that would work for both singlethread-JSPI/ASYNCIFY and proxied-from-background thread. Thats what #25970 is all about. Any help towards that goal is much appreciated! |
|
BTW, we don't have to actually mark a function as Marking a functions as |
Hmm true, we only need the async keyword to then use await (i think), but this is all just syntactic sugar at the end of the day. |
Hey, this isn't actually ready for merge - I just wanted to get a discussion going to figure out the correct way to implement this.
The quake3 engine uses select() with a timeout to throttle the server frame rate, while still allowing it to process network messages between frames. Using emscripten_set_main_loop doesn't work great here, as the server a.) is limited to handling networking at frame boundaries and b.) the timing isn't very consistent.
This PR doesn't contain an actual async poll implementation for the WebSocket backend - I added that on my wip WebTransport backend, which I'll post a separate PR for soon. However, the problem is still how to correctly handle making the syscall (and then everything else down the callstack that does async work) conditionally async. Sprinkling around
#if ASYNCIFYand__asyncdidn't feel great, but it did work.