1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Expose a simple Queue#wait to block until all notifications are drained

This commit is contained in:
Jeremy Kemper 2009-11-24 19:35:01 -08:00
parent 6f7fc5824f
commit ddf681ce1d
2 changed files with 8 additions and 3 deletions

View file

@ -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

View file

@ -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