Big week for plumbing! I overhauled the underlying implementation of Signals pretty thoroughly after encountering some surprises and I think I now have something that both matches my mental model and plays nice with the semantics of JavaScript generators. Some of the user facing syntax had to change slightly, but that's what "This package is a work in progress. Use at your own risk." is for 🙏
The main changes are connecting coroutines with yield*
instead of yield
. I had tried to make it so that users just used yield
to wait for anything and didn't have to think about it but unfortunately that's not how JavaScript works1. So the new syntax is:
yield
yield*
Also, any
and all
were refactored to be coroutines, so they are awaited with yield*
too.
This has to do with ensuring orderly cleanup of logic up and down the call stack when a coroutine is cancelled for any reason. We need to take advantage of the runtime managing the call stack and the implementation of try
/finally
to ensure cleanup logic in finally
clauses runs correctly.
This build introduces little health meters for the yachts and the orca and a very basic game over state when you've taken more damage than you can handle. The page is just refreshed afterwards -- real game loop coming next!
Full thing here. Any key after game over will just refresh the page. Real game loop coming soon!
There's a C# version of this system I am prototyping and I am pretty confident everything there will just wait with await
which is nice. ↩︎