abstract class Pulsar::TimedEvent
- Pulsar::TimedEvent
- Reference
- Object
Defined in:
pulsar/timed_event.crClass Method Summary
-
.subscribe(&block : self, Time::Span -> Nil)
Subscribe to events
Instance Method Summary
-
#name
Returns the name of the event.
-
#publish(&) : Time::Span
Publishes the event when the block finishes running.
-
#started_at
When the event started
Class Method Detail
def self.subscribe(&block : self, Time::Span -> Nil)
#
Subscribe to events
MyEvent.subscribe do |event, duration|
# Do something with the event and duration
end
MyEvent.new.publish do
# Do something
end
Instance Method Detail
def name
#
Returns the name of the event.
The event name is the name of the class. So an class of MyShard::MyEvent
would
return "MyShard::MyEvent"
.
def publish(&) : Time::Span
#
Publishes the event when the block finishes running.
Similar to Pulsar::Event#publish
but measures and publishes the time
it takes to run the block.
MyEvent.new.publish do
# Run some code
end
The #publish
method also returns the duration it took to run the block.