File: wait_for.rb

package info (click to toggle)
ruby-fog-core 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 684 kB
  • sloc: ruby: 4,812; makefile: 5
file content (17 lines) | stat: -rw-r--r-- 488 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module Fog
  def self.wait_for(timeout = Fog.timeout, interval = Fog.interval, &_block)
    duration = 0
    start = Time.now
    retries = 0
    loop do
      break if yield
      if duration > timeout
        raise Errors::TimeoutError, "The specified wait_for timeout (#{timeout} seconds) was exceeded"
      end

      sleep(interval.respond_to?(:call) ? interval.call(retries += 1).to_f : interval.to_f)
      duration = Time.now - start
    end
    { duration: duration }
  end
end