the idea is, before handling all events i open a resource....after all handlers have been called...i close the resources, i cant find an example where there is a relationship between the order the set_up and the tear_down is called, that's why we implemented a simple FIFO policy on both.
we thought that would be better to allow someone to define only tear down or only set_up...or both... independent from the common use cases, we wanted to give flexibility to the user, but maybe if you explain better the need of this syncronism between the set_up and the tear_down call it makes more sense to me.
As a final option, you might just want to let the signal itself define
set_up() and tear_down() and only call them if present:
function Signal:emit(...)
self.signal_stopped = false;
if self.set_up then
self.set_up()
end
for _, handler_table in ipairs(self.handlers) do
if(self.signal_stopped) then break end
if(handler_table.block == 0) then
handler_table.handler(...)
end
end
if self.tear_down then
self.tear_down()
end
end
The down side is that there would be only one of each (do you really
need multiples? can't the object take care of chaining them if necessary?).
well independent of my needs, i cant presume what will the user need, and why support only one set_up if i can support only one AND many if the user require? i think it is better to allow the user to decide that instead of obligating to have only one (since it is so simple to support more than one).