-
Notifications
You must be signed in to change notification settings - Fork 1
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
Beginning of AsyncGlk implementation #39
base: garglk
Are you sure you want to change the base?
Conversation
I'm now getting this error: Which is from the code
So I think I can't wait for a task like that, instead I have to use |
JS and .NET-in-WASM are inherently single-threaded, unfortunately. Task.Wait literally just means "block this thread until that task is done", but since there is no other thread available that could ever execute the task itself, we're not allowed to do this. Really, this is the reason why I wasn't too keen on making the JS/WASM interface a reality. The Adrift runner was built on WinForms' 'old-school' model of synchronous calls with nested event loops, and the existing standalone FrankenDrift apps use the Eto.Forms library specifically because it supports that model. I'll have to see whether it's possible to just introduce async/await everywhere without comprehensively destroying the existing frontends, or if we have to break this out into a whole separate "AsyncFD" project. (Either way, should Campbell Wild ever decide to make any changes to the Adrift code, this change means integrating them into FD will be even more of a nightmare than I imagine it already is.) Side note: how do the other wasm-compiled interpreters (tads, git, scare, etc.) handle this? I'd expect them to face similar issues... |
Looking at how the Glue API was designed, I think the async can be restricted to GlkRunner. I don't think the Adrift core or the Eto Forms runner will be impacted. If I'm wrong then we'll have to reconsider... The Emglken terps use Asyncify to run because the C Glk API is blocking. I don't think that's an issue with the dotnet browser-wasm because C# does have async/await. It's just one particular way of using async that won't work. Browser-wasm seems to run a .net interpreter compiled with Emscripten. So that means any C# async shouldn't be an issue despite the browser running single threaded, as it's being interpreted rather than running directly. |
So the changes required actually seem quite minor. So far I've only had to change these functions to be async:
I also changed it from directly calling
I ran into one hiccup which is that you can't I keep finding places where
From what I can tell, the windows are delayed only because of |
|
Actually it turns out threads are supported in browser-wasm, but it's looking possibly more difficult than making things async. |
Okay, so I have basic line and character input working, and I only needed to asyncify these extra functions:
What I've done is duplicate But I'm actually cheating... It feels fragile. Probably the solution will need everything to be converted to async. I really wish printing couldn't result in IO events! Why do so many IF platforms support it?! |
Then again, with the graphical nature of the Adrift editor I'm not sure where else you could stick the option to achieve similar flexibility. Also, it's almost a tradition for Adrift5 games (especially those by Larry Horsfield) to make their opening stanza a sort of title screen with lots of key-waiting; not supporting it from within |
Maybe it wouldn't really make a difference, but if the printing functions only ever just printed text and there were distinct functions that did the IO stuff then it would feel simpler! ;) So I've made most of the parser async now, and while a bit repetitive, it feels much safer to me. We are increasing the difference from upstream Adrift, but it is isolated to just a few files. I think it will be worth it. |
I tried doing it properly and making all the callers async, and it's just never ending. The code is so entwined and everything calls everything else. I think almost all of it would end up having to be converted. So I've given up. I pushed curiousdannii@b89b075 which is where I stopped. I'm going to go back to the threads option, see if I can work out how to get it working. Also VB not having destructuring is annoying! |
I think we need to wait for dotnet/runtime#68162 before the threading option is viable. Which means no Adrift 5 in JS for a while! So I'm going to shift my focus to adding some polish to the general GlkRunner implementation. |
This was meant to be a draft, but I can't see how to change it to a draft.