abstract class Pulsar::Event

Defined in:

pulsar/event.cr

Class Method Summary

Instance Method Summary

Instance methods inherited from class Pulsar::BaseEvent

name name

Class methods inherited from class Pulsar::BaseEvent

clear_subscribers clear_subscribers

Class Method Detail

def self.publish(*args_, **named_args_) #

Publishes the event to all subscribers.

MyEvent.publish

Passing arguments to initialize

If your event defines an initialize and requires arguments, you can pass those arguments to .publish.

For example if you had the event:

class MyEvent < Pulsar::Event
  def initialize(custom_argument : String)
  end
end

You would pass the arguments to .publish and they will be used to initialize the event:

MyEvent.publish(custom_argument: "This is my custom event argument")

[View source]
def self.subscribe(&block : self -> Nil) #

Subscribe to events

MyEvent.subscribe do |event|
  puts event.name # "MyEvent"
end

MyEvent.publish # Will run the block above

[View source]

Instance Method Detail

def started_at : Time #

When the event started