diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 7a9f76b26a0ec72ee7335ddd0f04f80f2db54fbf..09b1aa1713ab758f7eb50e1a586a766285b22bf6 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -154,10 +154,15 @@ def subscribe(pattern=nil, &block) @listeners << Listener.new(pattern, &block) end - def drained? - @listeners.all? &:drained? + def wait + sleep 0.05 until drained? end + private + def drained? + @listeners.all? &:drained? + end + class Listener def initialize(pattern, &block) @pattern = pattern diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 01106e83e97a723764d096cccae0a7305e667996..3df2088ac951bc2c4969fae3375a615481f941e8 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -201,6 +201,6 @@ def test_with_several_consumers_and_several_events private def drain - sleep(0.1) until ActiveSupport::Notifications.queue.drained? + ActiveSupport::Notifications.queue.wait end end