closer mixin
laforge49 opened this issue · comments
As we dynamically aggregate various mixins, we do need to track any required close functions. A closer mixin can do this with a stack.
For the closer mixin, we need two methods,
(on-close f opts)
(do-close opts)
The on-close method creates the closer mixin, if not already present, and adds f to the stack of close functions. This method is called when another mixin has a close function.
The do-close method then unwinds the stack, calling the various functions (or closures) in reverse order.
Completed draft. Note that the close function, f, can sometimes be called multiple times. F then really should be idempotent.
Second draft. The close function, f, no longer needs to be idempotent.
The get-close function can be used to make an open function idempotent. I.E. if (get-close f opts) returns null, then the on-close function has not yet been called.
tested, working
Logs close exceptions
Integrated with db-file
Two things. In practice, get-close is useless for ensuring that an open operation is idempotent.
Second, do-close needs to use a synchronization lock. There are just too many race conditions.
Rewrote closer. Is much simpler but uses locking. :-(
Rewrote closer without locking. Rah!
Updated options: https://github.com/laforge49/aatree/wiki/Options#closer-options
New closer page: https://github.com/laforge49/aatree/wiki/Closer
Updated the db file wiki page: https://github.com/laforge49/aatree/wiki/Db-File
Fixed a race condition