Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

reduce thread locals

  • Loading branch information...
commit e4de78aec504b885d40c0244ce3222c05ca3dc2e 1 parent a01d9da
@tenderlove tenderlove authored
Showing with 20 additions and 3 deletions.
  1. +20 −3 activesupport/lib/active_support/notifications.rb
View
23 activesupport/lib/active_support/notifications.rb
@@ -137,6 +137,23 @@ module ActiveSupport
module Notifications
@instrumenters = Hash.new { |h,k| h[k] = notifier.listening?(k) }
+ class Registry # :nodoc:
+ def self.instance
+ Thread.current[name] ||= new
+ end
+
+ attr_reader :notifier, :instrumenter
+
+ def initialize
+ self.notifier = Fanout.new
+ end
+
+ def notifier=(notifier)
+ @notifier = notifier
+ @instrumenter = Instrumenter.new(notifier)
+ end
+ end
+
class << self
def publish(name, *args)
notifier.publish(name, *args)
@@ -169,15 +186,15 @@ def unsubscribe(args)
end
def instrumenter
- Thread.current[:"instrumentation_#{notifier.object_id}"] ||= Instrumenter.new(notifier)
+ Registry.instance.instrumenter
end
def notifier
- Thread.current[:notifier] ||= Fanout.new
+ Registry.instance.notifier
end
def notifier=(notifier)
- Thread.current[:notifier] = notifier
+ Registry.instance.notifier = notifier
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.