Hi
This is just something I have been wondering about. I personally have
not yet found a use case for Lua's coroutines - the main reason being
that the resume has to be explicit. What would be more useful is if
the coroutine semantics could be harnessed to create an async/await
type solution as in C#. That is, can a solution be found to
automatically resume the coroutine when an event associated with a
'yield' completes. As Lua is single threaded so the solution needs to
resume the coroutine within the same OS thread.
I haven't really tried solving this but I thought it might be a useful
enhancement to Lua if a solution could be found. I imagine that a
background OS thread will be needed to monitor completion of events
and then some coordination with the VM will be necessary to resume
suspended coroutines, maybe whenever the VM does an operation that
requires system resources. In some ways the 'go' language works like
this - i.e. there is a background scheduler that swaps in suspended
goroutines to the thread whenever execution would otherwise pause.
This is just me thinking aloud, so please feel free to shoot it down,
or point me to existing solutions that achieve this (I imagine
projects that integrate libuv might be doing this already).
Thanks and Regards
Dibyendu