abstract class Pulsar::Event
- Pulsar::Event
- Pulsar::BaseEvent
- Reference
- Object
Defined in:
pulsar/event.crClass Method Summary
-
.publish(*args_, **named_args_)
Publishes the event to all subscribers.
-
.subscribe(&block : self -> Nil)
Subscribe to events
Instance Method Summary
-
#started_at : Time
When the event started
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")
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