aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2018-07-26 12:15:41 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2018-07-26 12:15:41 -0700
commit4cdedb571cc842ae9883a9b9754471ae3e82f698 (patch)
tree41297a56515e72657c6a679b468d2fcf0a642595 /activesupport/lib
parent5e0c423881985abfcbeffa602ee0d15467e24bf7 (diff)
downloadrails-4cdedb571cc842ae9883a9b9754471ae3e82f698.tar.gz
rails-4cdedb571cc842ae9883a9b9754471ae3e82f698.tar.bz2
rails-4cdedb571cc842ae9883a9b9754471ae3e82f698.zip
Always subscribe to event objects via `AS::Notifications.subscribe`
We don't need to have a special subscribe method for objects. The regular `subscribe` method is more expensive than a specialized method, but `subscribe` should not be called frequently. If that turns out to be a hotspot, we can introduce a specialized method. :)
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/notifications/fanout.rb19
-rw-r--r--activesupport/lib/active_support/notifications/instrumenter.rb2
2 files changed, 9 insertions, 12 deletions
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb
index 91d8491c7e..2fd683a1de 100644
--- a/activesupport/lib/active_support/notifications/fanout.rb
+++ b/activesupport/lib/active_support/notifications/fanout.rb
@@ -27,15 +27,6 @@ module ActiveSupport
subscriber
end
- def subscribe_event(pattern = nil, &block)
- subscriber = Subscribers.event_object_subscriber pattern, block
- synchronize do
- @subscribers << subscriber
- @listeners_for.clear
- end
- subscriber
- end
-
def unsubscribe(subscriber_or_name)
synchronize do
case subscriber_or_name
@@ -80,12 +71,16 @@ module ActiveSupport
module Subscribers # :nodoc:
def self.new(pattern, listener)
if listener.respond_to?(:start) && listener.respond_to?(:finish)
- subscriber = Evented.new pattern, listener
+ subscriber_class = Evented
else
- subscriber = Timed.new pattern, listener
+ if listener.respond_to?(:arity) && listener.arity == 1
+ subscriber_class = EventObject
+ else
+ subscriber_class = Timed
+ end
end
- wrap_all pattern, subscriber
+ wrap_all pattern, subscriber_class.new(pattern, listener)
end
def self.event_object_subscriber(pattern, block)
diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb
index 72e5064679..455b7a44a6 100644
--- a/activesupport/lib/active_support/notifications/instrumenter.rb
+++ b/activesupport/lib/active_support/notifications/instrumenter.rb
@@ -69,12 +69,14 @@ module ActiveSupport
@allocation_count_finish = 0
end
+ # Record information at the time this event starts
def start!
@time = now
@cpu_time_start = now_cpu
@allocation_count_start = now_allocations
end
+ # Record information at the time this event finishes
def finish!
@cpu_time_finish = now_cpu
@end = now