A Custodian keeps a set of actors to dispose. When the Custodian is disposed, it disposes of the actors in its set and then clears the set.
Imagine you have a program with 3 actors that you need to shutdown when it receives a TERM signal. We can set up a Custodian that knows about each of our actors and when a TERM signal is received, is disposed of.
use "bureaucracy"
use "signals"
actor Actor1
  be dispose() => None // dispose of resources here.
actor Actor2
  be dispose() => None // dispose of resources here.
actor Actor3
  be dispose() => None // dispose of resources here.
actor Main
  new create(env: Env) =>
    let actor1 = Actor1
    let actor2 = Actor2
    let actor3 = Actor3
    let custodian = Custodian
    custodian(actor1)
    custodian(actor2)
    custodian(actor3)
    SignalHandler(TermHandler(custodian), Sig.term())
class TermHandler is SignalNotify
  let _custodian: Custodian
  new iso create(custodian: Custodian) =>
    _custodian = custodian
  fun ref apply(count: U32): Bool =>
    _custodian.dispose()
    true
 actor tag Custodian
new tag create() : Custodian tag^
Add an actor to be disposed of.
be apply( worker: DisposableActor tag)
Removes an actor from the set of things to be disposed.
be remove( worker: DisposableActor tag)
Dispose of the actors in the set and then clear the set.
be dispose()
    © 2016-2018, The Pony Developers
© 2014-2015, Causality Ltd.
Licensed under the BSD 2-Clause License.
    https://stdlib.ponylang.io/bureaucracy-Custodian