[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: yield from __close
- From: Marcus Mason <m4gicks@...>
- Date: Thu, 22 Oct 2020 07:43:15 +0100
I would also really like to see this feature added, sounds very interesting!
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
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 :-)