Skip to content

class Athena::EventDispatcher::Event
inherits Reference #

Base class for all event objects.

This event does not contain any event data and can be used by events that do not require any state.

Can be inherited from to include information about the event.

NOTE: If one event inherits from another, and both are being used within a listener; the child event's handler would be executed twice since its type is compatible with the parent. Either use composition versus inheritance for sharing common logic between events, or add an explicit type check in the listener.

# Define a custom event
class ExceptionEvent < AED::Event
  getter exception : Exception

  def initialize(@exception : Exception); end

# Using Event on its own

# Dispatch a custom event
exception = "Value cannot be negative"
dispatcher.dispatch exception