class Dry::Monitor::Notifications

Attributes

clock[R]
id[R]

Public Class Methods

new(id) click to toggle source
# File lib/dry/monitor/notifications.rb, line 27
def initialize(id)
  @id = id
  @clock = CLOCK
end

Public Instance Methods

instrument(event_id, payload = EMPTY_HASH, &block) click to toggle source
# File lib/dry/monitor/notifications.rb, line 40
def instrument(event_id, payload = EMPTY_HASH, &block)
  result, time = @clock.measure(&block) if block_given?

  process(event_id, payload) do |event, listener|
    if time
      listener.(event.payload(payload.merge(time: time)))
    else
      listener.(event)
    end
  end

  result
end
start(event_id, payload) click to toggle source
# File lib/dry/monitor/notifications.rb, line 32
def start(event_id, payload)
  instrument(event_id, payload)
end
stop(event_id, payload) click to toggle source
# File lib/dry/monitor/notifications.rb, line 36
def stop(event_id, payload)
  instrument(event_id, payload)
end