Coroutines in EFL
Since users do not get callbacks, let's allow them to write
"synchronous" code that cooperates with the main loop.
This allows eina_coro_yield() to cooperatively give back control to
the main loop and ask to be rescheduled later, a common pattern we use
with a bunch of functions -- one to schedule, one for callback, one to
save context, other to free context.
And it is possible to await on a future of a promise to be resolved
with eina_coro_await() (or eina_future_await() helper). These will
allow for even simpler code and efficient scheduling -- the coroutine
is put to sleep until the future resolves.
Since there are no platform independent ways to save and restore a
function context (makecontext()/swapcontext() doesn't work on all
platforms) and I'm not willing to waste time with manual assembly for
each platform the initial implementation uses
Eina_Thred/Eina_Lock/Eina_Condition to do it. However the API allows
to change to single-thread coroutines -- code is also simple to
"ifdef" shall we come to an agreement: _eina_coro_signal() and
This is not about efficiency, more on ease of use and targeted at end
users, such as application developers. See _await() function in
ecore_test_promise2.c, it does the traditional "sleep()" without
blocking the main thread and is as simple to use -- if this becomes a
common pattern we can introduce efl_loop_coro_sleep(loop, coro,
seconds) to make it a single-line.