lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I would also really like to see this feature added, sounds very interesting!

On Wed, Oct 7, 2020 at 1:15 PM John Belmonte <john@neggie.net> wrote:
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.


On Sat, Oct 3, 2020 at 1:40 AM Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> 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