Permalink
Browse files

Merge pull request #10285 from wangjohn/subscriber_registry

Created a registry for ActiveSupport::Subscriber queues
  • Loading branch information...
2 parents a429993 + be7e34b commit f95b06f96faa009b7d2523c3c244ca6d8512e373 @carlosantoniodasilva carlosantoniodasilva committed Apr 22, 2013
Showing with 20 additions and 2 deletions.
  1. +20 −2 activesupport/lib/active_support/subscriber.rb
@@ -1,3 +1,5 @@
+require 'active_support/per_thread_registry'
+
module ActiveSupport
# ActiveSupport::Subscriber is an object set to consume
# ActiveSupport::Notifications. The subscriber dispatches notifications to
@@ -68,8 +70,24 @@ def finish(name, id, payload)
private
- def event_stack
- Thread.current[@queue_key] ||= []
+ def event_stack
+ SubscriberQueueRegistry.get_queue(@queue_key)
+ end
+ end
+
+ # This is a registry for all the event stacks kept for subscribers.
+ #
+ # See the documentation of <tt>ActiveSupport::PerThreadRegistry</tt>
+ # for further details.
+ class SubscriberQueueRegistry # :nodoc:
+ extend PerThreadRegistry
+
+ def initialize
+ @registry = {}
+ end
+
+ def get_queue(queue_key)
+ @registry[queue_key] ||= []
end
end
end

0 comments on commit f95b06f

Please sign in to comment.