EventHandler::Subscription
Inherits Reference < Object
A single event subscription that remembers how to cancel itself.
The target is captured at subscribe time inside the cancel closure, so
#off always removes from the exact object it added to, regardless of
where the owner later points. #off is idempotent, so two teardown paths
can both call it without double-freeing; #on cancels any previous handler
first, so a slot re-armed repeatedly can't leak.
target is any EventHandler includer (duck-typed: anything with the
generated on(type, ...)/off(type, wrapper) pair).
Constructors
A subscription over an already-installed handler: cancel removes it.
This is the form the generated EventHandler#on/#once return, so
every subscription — whether built here or handed out by on — tears
down through the same idempotent #off.
live, when given, reports whether the handler is still installed
(see #live?).
Instance methods
Whether this subscription still holds a cancel, i.e. has not been torn
down through #off. It does not track the handler's presence on the
emitter: a once handler that auto-fired, or one removed through
off(type, ...)/remove_all_handlers, leaves the subscription active
until its own #off (a no-op by then).
dispose/disposed? aliases of #off/!active?, for callers whose
teardown vocabulary is dispose (e.g. reactive stacks). #off stays the
canonical spelling (it mirrors on/off).
The registered handler's identity hash (Wrapper#handler_hash), for the
off(type, hash) bulk-removal form. Raises ArgumentError when this
subscription holds no wrapper (see #wrapper).
Whether the handler behind this subscription is still installed on its
emitter. Unlike #active? this does track the handler: it turns false
once a once handler has fired, or the handler was removed through
off(type, ...)/remove_all_handlers, as well as after #off. A
plain teardown block (Subscriptions#add) is live until its #off.
Subscribes block to event type on target, first cancelling any
handler this slot already holds. Returns self.
The Wrapper behind this subscription (in the erased
Wrapper(Proc(Event, Nil)) form AddHandlerEvent listeners also get),
once the generated on/once returned it or #on armed it. nil for
an empty slot and for a plain teardown block (Subscriptions#add).