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:



234
235
236
237
238
239
240
241
242
# File 'lib/active_support/notifications/fanout.rb', line 234

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



253
254
255
# File 'lib/active_support/notifications/fanout.rb', line 253

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

#finish_with_values(name, id, payload) ⇒ Object

:nodoc:



257
258
259
260
261
262
263
264
# File 'lib/active_support/notifications/fanout.rb', line 257

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



244
245
246
247
248
249
250
251
# File 'lib/active_support/notifications/fanout.rb', line 244

def start
  ensure_state! :initialized
  @state = :started

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