class

EventHandler::Wrapper(T)

Inherits Reference < Object

Generic class wrapping each installed handler.

Not generally used directly; implicitly created by on() (reachable as Subscription#wrapper on the subscription it returns), and sent as an argument to emitted AddHandlerEvent/RemoveHandlerEvent events.

Holds each handler's once, async, and at settings. at is the position the wrapper is inserted at in the handler list, on every registration (clamped to the list's bounds, so a position past the end means the end); mostly useful to check for 0 or -1, meaning the beginning or the end of the list.

Constructors

new(handler : T, once : Bool = false, async : Bool = ::EventHandler.async?, at : Int32 = ::EventHandler.at_end, hash = nil)
Source
new(once = false, async = ::EventHandler.async?, at = ::EventHandler.at_end, hash = nil, &handler : T)
Source

Instance methods

async?
Source
call(obj, async = nil)

Dispatches obj to the wrapped handler and returns obj.

Handlers are Proc(T, Nil), so their own return conveys nothing; returning the dispatched event instead lets wait(type, handler)/ wait(type) { ... } yield it, matching the handler-less wait overloads. The async branch also returns obj even though the handler runs in its own fiber. _emit ignores this return value, so dispatch is unaffected.

Source
clone

A new wrapper around the same handler, with the same settings and handler_hash. Registrations are per wrapper object, so the clone is registered and removed independently of the original. Also what the clone of an AddHandlerEvent/RemoveHandlerEvent copies.

A field-for-field copy rather than a new: the wrapper is often held in the erased Wrapper(Proc(Event, Nil)) spelling, where constructing one would record Event as the event_type and let the clone be registered for events its handler cannot take.

Source
event_type

The event type the wrapped handler accepts: Ev for a Wrapper(Proc(Ev, Nil)). Kept in the object rather than derived from T because the wrapper is often held in the erased Wrapper(Proc(Event, Nil)) spelling (Subscription#wrapper, the meta events), where T no longer tells; the generated on(type, wrapper) reads it to refuse a wrapper whose handler cannot take type.

Source
handler
Source
handler_hash
Source
once?
Source