lua-users home
lua-l archive

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


On Fri, Jul 31, 2020 at 8:54 PM Dibyendu Majumdar wrote:
All I was saying is that the 'defer' statement makes less promises as
it makes it more explicit that some code (it can anything) will be
executed when the scope is exited.
But basically that is all that to-be-closed variables do - a promise
to run some code if the scope is exited. They do not promise to close
anything. They are not finalizers.
And because they are what they are, if a thread does not exit scope
they will never run.

We don't need just a "scope exit event".
The point of why to-be-closed variables exist: we need a "predictable finalizer".
We need to guarantee that a resource will be closed as fast as possible,
whatever happened in the code.