Class: ActiveSupport::Notifications::Fanout::Handle
- 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
- #finish ⇒ Object
-
#finish_with_values(name, id, payload) ⇒ Object
:nodoc:.
-
#initialize(notifier, name, id, payload) ⇒ Handle
constructor
:nodoc:.
- #start ⇒ Object
Constructor Details
#initialize(notifier, name, id, payload) ⇒ Handle
:nodoc:
230 231 232 233 234 235 236 237 238 |
# File '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
#finish ⇒ Object
249 250 251 |
# File 'lib/active_support/notifications/fanout.rb', line 249 def finish finish_with_values(@name, @id, @payload) end |
#finish_with_values(name, id, payload) ⇒ Object
:nodoc:
253 254 255 256 257 258 259 260 |
# File '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 ⇒ Object
240 241 242 243 244 245 246 247 |
# File '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 |