1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/core/wait_for.rb

16 lines
407 B
Ruby
Raw Normal View History

2010-12-16 14:24:52 -05:00
module Fog
2011-07-11 18:06:47 -04:00
def self.wait_for(timeout=Fog.timeout, interval=1, &block)
2010-12-16 14:24:52 -05:00
duration = 0
start = Time.now
until yield || duration > timeout
sleep(interval.to_f)
2010-12-16 14:24:52 -05:00
duration = Time.now - start
end
if duration > timeout
raise Errors::TimeoutError.new("The specified wait_for timeout (#{timeout} seconds) was exceeded")
2010-12-16 14:24:52 -05:00
else
{ :duration => duration }
end
end
end