By Phil Nash
Coroutines seem to work like magic - with the compiler generating a lot of machinery for you. Yet, at the same time, writing them from scratch remains complex with lots of moving parts! Trying to keep them all in your head while learning it is what makes coroutines so hard to master.
But the dance between all those parts and what the compiler does for you is so tight that you can literally let your compiler be your guide. I’ll show how, from a standing start, you can get from no code to a working, useful, coroutine while only needing to know a handful of extra pieces of information.
In ancient Greek theatre puzzling plots were often resolved by external factors - often an actor or prop lowered in from a crane (in Greek, "mēkhanês", or Latin: "mechine"). This came to be called, "deus ex machina" - gods from the machine. We will keep our deus ex machina to a minimum and leave the compiler to teach us the rest.
Finally! Coroutines without the suspense!










