module Onyx::EDA::Subscriber(T)


A module which would make an including object an event subscriber. Subscribers are notified about every incoming event of type T.

A single object can have multiple Subscriber and Consumer modules included, just make sure you have #handle method defined for each event.

NOTE You can not have both Subscriber and Consumer modules included for a single event type.

A single actor instance (this module includes Actor module) can be subscribed to multiple channels simultaneously.

TODO Have an internal buffer to filter repeating (i.e. with the same ID) events among multiple channels.

class Actor::Logger
  include Onyx::EDA::Subscriber(Event::User::Registered)
  include Onyx::EDA::Consumer(Event::Payment::Successfull)

  # This method will be called in *all* Actor::Logger instances
  def handle(event : Event::User::Registered)
    log_into_terminal("New user with id #{}")

  # This method will be called in only *one* Actor::Logger instance
  def handle(event : Event::Payment::Successfull)
    send_email("[email protected]", "New payment of $#{event.amount}")

actor =
actor.subscribe(channel) # Non-blocking method
# ...

Included Modules

Defined in:


Instance Method Summary

Instance methods inherited from module Onyx::EDA::Actor

subscribe(channel : Onyx::EDA::Channel) : self subscribe, unsubscribe(channel : Onyx::EDA::Channel) : self unsubscribe

Instance Method Detail

abstract def handle(event : T) #

Handle incoming event. Must be defined explicitly in a consumer.

TODO Find a way to enable per-event filtering.

[View source]