I will try to explain in greater detail what I am trying to achieve and why I thought coroutines would be great for that. (This is a continuation of the previous thread called "Garbage collected coroutines?" which I am unable to reply to.)
I am experimenting with a way to generate musical waveforms using scripts. The script generates random melodies, renders them as tones, mixes those tones together and writes the resulting music to WAV file (or plays it directly using aplay on Linux).
So, the output of my script is a waveform consisting of 48000 samples per second.
Previously I've experimented with this in Lua a Janet where I was able to do the following:
There is an endless loop, let's call it "audio-out" that writes the resulting WAV file to disk (or plays it in semi-realtime).