Skip to content

abstract struct Athena::EventDispatcher::Callable
inherits Struct #

Encapsulates everything required to represent an event listener. Including what event is being listened on, the callback itself, and its priority.

Each subclass represents a specific "type" of listener. See each subclass for more information.


These types can be manually instantiated and added via the related AED::EventDispatcherInterface#listener(callable) overload. This can be useful as a point of integration to other libraries, such as lazily instantiating a AED::EventListenerInterface instance.


Each callable also has an optional name that can be useful for debugging to allow identifying a specific callable since there would be no way to tell apart two listeners on the same event, with the same priority.

class MyEvent < AED::Event; end

dispatcher =

dispatcher.listener(MyEvent) { }
dispatcher.listener(MyEvent, name: "block-listener") { }

class MyListener
  include AED::EventListenerInterface

  def on_my_event(event : MyEvent) : Nil


dispatcher.listeners(MyEvent).map &.name # => ["unknown callable", "block-listener", "MyListener#on_my_event"]

AED::Callable::EventListenerInstance instances registered via AED::EventDispatcherInterface#listener(listener) will automatically have a name including the method and listener class names in the format of ClassName#method_name.

Included modules


Direct known subclasses

Athena::EventDispatcher::Callable::Event(E) Athena::EventDispatcher::Callable::EventDispatcher(E) Athena::EventDispatcher::Callable::EventListenerInstance(I, E)


.new(event_class : AED::Event.class, name : String | Nil, priority : Int32)#

View source


#event_class : AED::Event.class#

Returns what AED::Event class this callable represents.

View source

#name : String#

Returns the name of this callable. Useful for debugging to identify a specific callable added from a block, or which method an AED::Callable::EventListenerInstance is associated with.

View source

#priority : Int32#

Returns the listener priority of this callable.

View source