Please keep "yield from __close" in mind for the next version of Lua.
In Python there have been efforts to make limited asyncio support available for tiny environments (MicroPython, etc.). However, supporting the structured concurrency libraries on top of that doesn't appear feasible due to the heavy dependencies.
With this feature, Lua could have async context managers (blocking for I/O on scope exit) and support structured concurrency. Moreover, this would run on microcontrollers and embedded applications without effort. Having high-level concurrency constructs from a scripting language in such environments would set a new precedent.
Regards,
--John
I think it would be worth it. It enables, for example, anything that can be done today using Python's async context managers (including structured concurrency).
I have the start of a structured concurrency implementation prototyped in about 200 lines of Lua. Fairly exciting, and I was looking forward to posting some articles as things progressed-- but the yield issue is a show stopper.
> Being able to block at scope exit (in Lua, from a "__close" metamethod hand
> control back to the coroutine scheduler via "yield") is fundamental to
> implementing structured concurrency.
>
> Would there be any way to lift this restriction from the to-be-closed
> implementation?
I don't see any conceptual problem, but I don't have a clear idea of how
hard it would be to implement it.
It seems that we could add a bit in callstatus that we are running a
"__close" metamethod and then allow yields. In case of yield, after
finishing the function, 'unroll' have to check that bit and, if true,
continue the interrupted work (remove the upvalue from the list and
run the other pending closes).
All very slippery code :-)
-- Roberto