Comment by vintagedave
1 month ago
> automatically yields after each logical line of code
I've become more and more interested in code that yields (coroutines etc, read this fascinating article on HN just a couple of days ago: https://willhbr.net/2026/03/02/async-inject-and-effects/ )
Can you share more about this? How the async model works? Why it does -- is it a performance guarantee given the RTOS comment? Or is it more about the state machine idea, and how or why does yielding every line (not, say, every state transition, though I have no idea if or why that would be more useful) relate to that?
I mostly just have lots of questions because it sounds fascinating, so if you're looking for an excuse to talk about it, please count this as that excuse!
The idea is not so much any kind of hard real time guarantee (in practice it switches quickly so it is soft realtime) but what you often have when doing bare-metal embedded systems is a lot of parallel state machines, not necessarily because the state machine is the best mechanism it's more because you want things to happen in parallel in C/C++, this can be annoying to deal with so you end up with these statemachines that don't block, you cycle through them, and you get "parallel" operation, but anything can block other statemachines, and things like long running for loops need to be broken into non blocking states. I've often thought an Actor Model like thing would be really nice if baked into the language and that the actors were all "live" such that were all processing in parallel and firing off events as needed which is how I started this. I initially was thinking switching on something like state transitions / explicit yields but every statement yielding automatically lets you run multiple "forever" loops which in turn might have long running for loops (like updating a display) statement switching means you don't have to worry about when to yield. Instead I reversed it and figured it would be nicer to define things that need to run as an atomic operation as that seems to be less frequent. This way you generally don't need to worry about blocking and it feels like it's programming as if it was pre-emptive multitasking. Multiple little programs all concurrently running and firing off events to communicate with each other