aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-11-24 19:35:01 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2009-11-28 12:50:09 -0800
commitddf681ce1d3e71aef913dd7f94c60b7622523f8b (patch)
tree68e318096f625119997eab90f1977744f7f4d57c /activesupport
parent6f7fc5824f2033c0f674b002dbee7f1c3f3384ac (diff)
downloadrails-ddf681ce1d3e71aef913dd7f94c60b7622523f8b.tar.gz
rails-ddf681ce1d3e71aef913dd7f94c60b7622523f8b.tar.bz2
rails-ddf681ce1d3e71aef913dd7f94c60b7622523f8b.zip
Expose a simple Queue#wait to block until all notifications are drained
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/notifications.rb9
-rw-r--r--activesupport/test/notifications_test.rb2
2 files changed, 8 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb
index 7a9f76b26a..09b1aa1713 100644
--- a/activesupport/lib/active_support/notifications.rb
+++ b/activesupport/lib/active_support/notifications.rb
@@ -154,10 +154,15 @@ module ActiveSupport
@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 01106e83e9..3df2088ac9 100644
--- a/activesupport/test/notifications_test.rb
+++ b/activesupport/test/notifications_test.rb
@@ -201,6 +201,6 @@ class NotificationsMainTest < Test::Unit::TestCase
private
def drain
- sleep(0.1) until ActiveSupport::Notifications.queue.drained?
+ ActiveSupport::Notifications.queue.wait
end
end