Class: ActiveSupport::Notifications::Fanout::Handle

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Notifications::FanoutIteration
Defined in:
lib/active_support/notifications/fanout.rb

Overview

A Handle is used to record the start and finish time of event.

Both #start and #finish must each be called exactly once.

Where possible, it’s best to use the block form: ActiveSupport::Notifications.instrument. Handle is a low-level API intended for cases where the block form can’t be used.

handle = ActiveSupport::Notifications.instrumenter.build_handle("my.event", {})
begin
  handle.start
  # work to be instrumented
ensure
  handle.finish
end

Instance Method Summary collapse

Constructor Details

#initialize(notifier, name, id, payload) ⇒ Handle

:nodoc:



231
232
233
234
235
236
237
238
239
# File 'lib/active_support/notifications/fanout.rb', line 231

def initialize(notifier, name, id, payload) # :nodoc:
  @name = name
  @id = id
  @payload = payload
  @groups = notifier.groups_for(name).map do |group_klass, grouped_listeners|
    group_klass.new(grouped_listeners, name, id, payload)
  end
  @state = :initialized
end

Instance Method Details

#finishObject



250
251
252
# File 'lib/active_support/notifications/fanout.rb', line 250

def finish
  finish_with_values(@name, @id, @payload)
end

#finish_with_values(name, id, payload) ⇒ Object

:nodoc:



254
255
256
257
258
259
260
261
# File 'lib/active_support/notifications/fanout.rb', line 254

def finish_with_values(name, id, payload) # :nodoc:
  ensure_state! :started
  @state = :finished

  iterate_guarding_exceptions(@groups) do |group|
    group.finish(name, id, payload)
  end
end

#startObject



241
242
243
244
245
246
247
248
# File 'lib/active_support/notifications/fanout.rb', line 241

def start
  ensure_state! :initialized
  @state = :started

  iterate_guarding_exceptions(@groups) do |group|
    group.start(@name, @id, @payload)
  end
end