EventHandler::Subscriptions
Inherits Reference < Object
A bag of Subscriptions that are torn down together. #on adds a tracked
subscription and returns it, so a single one can still be re-armed or
cancelled individually; #add tracks a subscription made elsewhere, or a
plain teardown block; #off cancels every remaining one, idempotently.
Subscriptions that are no longer live (Subscription#live?: cancelled
individually, or a once handler that fired) are dropped from the bag as
it grows, so a long-lived bag does not accumulate them, nor keep their
handlers' closures alive.
Like the standard collections, neither class is synchronized: share one
between fibers running in parallel only under your own lock. (The
emitter's on/off/emit are safe to call in parallel.)
Instance methods
Tracks a teardown that is not an event subscription — a listener
registered with a config option, a timer, a file watcher — so the bag's
#off cancels it with the rest. cancel runs once, at the bag's #off
or at the returned Subscription's own, whichever comes first. Returns
the created Subscription.
handle = Config.on_change("app.theme") { apply_theme }
subs.add { Config.off_change "app.theme", handle }
Tracks an existing subscription, such as one EventHandler#on
returned, for the bag's bulk #off. Returns it.
Cancels every tracked subscription and empties the bag. Idempotent.
Every subscription is cancelled even if one raises: the bag is emptied first, each remaining one is still torn down, and the first exception is re-raised at the end.
Subscribes block to type on target, tracking it for a later bulk
#off. Returns the created Subscription.