123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::ServerTiming::Subscriber

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, ::Singleton
Inherits: Object
Defined in: actionpack/lib/action_dispatch/middleware/server_timing.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

::Singleton - Included

#duplicable?

::Singleton instances are not duplicable:

Instance Method Summary

Constructor Details

.newSubscriber

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/server_timing.rb', line 13

def initialize
  @mutex = Mutex.new
end

Instance Method Details

#call(event)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/server_timing.rb', line 17

def call(event)
  if events = ActiveSupport::IsolatedExecutionState[KEY]
    events << event
  end
end

#collect_events

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/server_timing.rb', line 23

def collect_events
  events = []
  ActiveSupport::IsolatedExecutionState[KEY] = events
  yield
  events
ensure
  ActiveSupport::IsolatedExecutionState.delete(KEY)
end

#ensure_subscribed

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/server_timing.rb', line 32

def ensure_subscribed
  @mutex.synchronize do
    # Subscribe to all events, except those beginning with "!" Ideally we would be
    # more selective of what is being measured
    @subscriber ||= ActiveSupport::Notifications.subscribe(/\A[^!]/, self)
  end
end

#unsubscribe

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/server_timing.rb', line 40

def unsubscribe
  @mutex.synchronize do
    ActiveSupport::Notifications.unsubscribe @subscriber
    @subscriber = nil
  end
end