abstract class Pulsar::TimedEvent

Defined in:

pulsar/timed_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 when the block finishes running.

Similar to Pulsar::Event#publish but measures and publishes the time it takes to run the block.

MyEvent.publish do
  # Run some code
end

The .publish method returns the result of the block.

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::TimedEvent
  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") do
  # ...run some code
end

[View source]
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.publish do
  # Do something
end

[View source]

Instance Method Detail

def started_at : Time #

When the event started