123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: activesupport/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

Class Method Summary

Instance Method Summary

Constructor Details

.new(notifier, name, id, payload) ⇒ Handle

This method is for internal use only.
[ GitHub ]

  
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 230

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

#ensure_state!(expected) (private)

[ GitHub ]

  
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 263

def ensure_state!(expected)
  if @state != expected
    raise ArgumentError, "expected state to be #{expected.inspect} but was #{@state.inspect}"
  end
end

#finish

[ GitHub ]

  
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 249

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

#finish_with_values(name, id, payload)

This method is for internal use only.
[ GitHub ]

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

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

#start

[ GitHub ]

  
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 240

def start
  ensure_state! :initialized
  @state = :started

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