diff options
| author | wangjohn <wangjohn@mit.edu> | 2013-04-21 11:39:48 -0400 | 
|---|---|---|
| committer | wangjohn <wangjohn@mit.edu> | 2013-04-22 09:18:37 -0400 | 
| commit | be7e34bc1ef81a5c78a86be7201d3aab5106978b (patch) | |
| tree | fb30a825a08a1e4e202dd04243c3e8118e4abae3 | |
| parent | a4299937423138caf9e0018c50649cd12d63fd32 (diff) | |
| download | rails-be7e34bc1ef81a5c78a86be7201d3aab5106978b.tar.gz rails-be7e34bc1ef81a5c78a86be7201d3aab5106978b.tar.bz2 rails-be7e34bc1ef81a5c78a86be7201d3aab5106978b.zip  | |
Created a registry based on the +PerThreadRegistry+ module for
subscriber queues. Helps limit the number of thread locals.
| -rw-r--r-- | activesupport/lib/active_support/subscriber.rb | 22 | 
1 files changed, 20 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/subscriber.rb b/activesupport/lib/active_support/subscriber.rb index ab76cf5c85..34c6f900c1 100644 --- a/activesupport/lib/active_support/subscriber.rb +++ b/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 @@ module ActiveSupport      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  | 
