Class: ActionDispatch::ServerTiming::Subscriber
- Inherits:
-
Object
- Object
- ActionDispatch::ServerTiming::Subscriber
- Includes:
- Singleton
- Defined in:
- 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
Constructor Details
#initialize ⇒ Subscriber
Returns a new instance of Subscriber.
11 12 13 |
# File 'lib/action_dispatch/middleware/server_timing.rb', line 11 def initialize @mutex = Mutex.new end |
Instance Method Details
#call(event) ⇒ Object
15 16 17 18 19 |
# File 'lib/action_dispatch/middleware/server_timing.rb', line 15 def call(event) if events = ActiveSupport::IsolatedExecutionState[KEY] events << event end end |
#collect_events ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/action_dispatch/middleware/server_timing.rb', line 21 def collect_events events = [] ActiveSupport::IsolatedExecutionState[KEY] = events yield events ensure ActiveSupport::IsolatedExecutionState.delete(KEY) end |
#ensure_subscribed ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/action_dispatch/middleware/server_timing.rb', line 30 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
38 39 40 41 42 43 |
# File 'lib/action_dispatch/middleware/server_timing.rb', line 38 def unsubscribe @mutex.synchronize do ActiveSupport::Notifications.unsubscribe @subscriber @subscriber = nil end end |