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:
parent
6f7fc5824f
commit
ddf681ce1d
2 changed files with 8 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue