Class: ActionDispatch::ServerTiming::Subscriber
- Includes:
 - Singleton
 
- Defined in:
 - actionpack/lib/action_dispatch/middleware/server_timing.rb
 
Overview
:nodoc:
Constant Summary collapse
- KEY =
 :action_dispatch_server_timing_events
Instance Method Summary collapse
- #call(event) ⇒ Object
 - #collect_events ⇒ Object
 - #ensure_subscribed ⇒ Object
 - 
  
    
      #initialize  ⇒ Subscriber 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Subscriber.
 - #unsubscribe ⇒ Object
 
Methods included from Singleton
Constructor Details
#initialize ⇒ Subscriber
Returns a new instance of Subscriber.
      13 14 15  | 
    
      # File 'actionpack/lib/action_dispatch/middleware/server_timing.rb', line 13 def initialize @mutex = Mutex.new end  | 
  
Instance Method Details
#call(event) ⇒ Object
      17 18 19 20 21  | 
    
      # 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 ⇒ Object
      23 24 25 26 27 28 29 30  | 
    
      # 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 ⇒ Object
      32 33 34 35 36 37 38  | 
    
      # 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 ⇒ Object
      40 41 42 43 44 45  | 
    
      # File 'actionpack/lib/action_dispatch/middleware/server_timing.rb', line 40 def unsubscribe @mutex.synchronize do ActiveSupport::Notifications.unsubscribe @subscriber @subscriber = nil end end  |