16.3 Will Executors
| import: rhombus/will | package: rhombus-lib |
A will executor support finalization by maintaining a collection of will functions associated to Rhombus objects. When an object becomes unreachable, its will are ready to be executed. See Wills and Will Executors for more information.
A will executor can be used as a synchronizable event. A will executor is ready for synchronization when will.Executor.execute would not block, and the synchronization result is the executor itself.
The v_will argument is strongly referenced by executor until it is executed, which is why v is supplied back to v_will instead of expecting v to be in v_will’s closure.
See will.Executor.execute for an example.
method | |||
| |||
method | |||
|
If no will is ready for immediate execution, will.Executor.execute blocks until one is ready, while will.Executor.maybe_execute returns none immediately.
The following example reflects a relatively simple pattern where will functions can run at any time, so a thread is created to run wills as soon as they become available.
def th:
thread:
while #true:
fun (bx):
println("a-box is now garbage"))
memory.gc()
box_to_track := #false
memory.gc()
// printing is likely at this point
#void