struct

Athena::EventDispatcher::Callable

Inherits Comparable < Struct < Value < Object

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.

TIP: 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 listener instances.

Name

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 = AED::EventDispatcher.new

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

class MyListener
  @[AEDA::AsEventListener]
  def on_my_event(event : MyEvent) : Nil
  end
end

dispatcher.listener MyListener.new

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.

Constructors

new(event_class : ACTR::EventDispatcher::Event.class, name : String | Nil, priority : Int32)
Source

Instance methods

event_class

Returns what ACTR::EventDispatcher::Event class this callable represents.

Source
name

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.

Source
priority

Returns the [listener priority][Athena::EventDispatcher::EventDispatcherInterface--listener-priority] of this callable.

Source

Nested types