diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-11-13 20:58:38 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-11-13 20:58:38 -0800 |
commit | 58c0d31487d158286576b0745a55a0941ed076ad (patch) | |
tree | 41d08ab44a89d1a1fddccfe6443f7578a5fb29fe /activesupport/lib | |
parent | 66fda6b8949cde07966ab098125e1da7969e9468 (diff) | |
download | rails-58c0d31487d158286576b0745a55a0941ed076ad.tar.gz rails-58c0d31487d158286576b0745a55a0941ed076ad.tar.bz2 rails-58c0d31487d158286576b0745a55a0941ed076ad.zip |
Notifications: queue.drained? for testability in place of brittle sleeps
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/notifications.rb | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 6304f496f5..7a9f76b26a 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -144,27 +144,21 @@ module ActiveSupport class LittleFanout def initialize @listeners = [] - @stream = Queue.new - Thread.new { consume } end def publish(*args) - @stream.push(args) + @listeners.each { |l| l.publish(*args) } end def subscribe(pattern=nil, &block) @listeners << Listener.new(pattern, &block) end - def consume - while args = @stream.shift - @listeners.each { |l| l.publish(*args) } - end + def drained? + @listeners.all? &:drained? end class Listener - # attr_reader :thread - def initialize(pattern, &block) @pattern = pattern @subscriber = block @@ -183,6 +177,10 @@ module ActiveSupport @subscriber.call(*args) end end + + def drained? + @queue.size.zero? + end end end end |