Module: YuiRestClient::Timer

Defined in:
lib/yui_rest_client/timer.rb

Class Method Summary collapse

Class Method Details

.wait(timeout, interval) ⇒ Object

Execute code block with the interval until timeout reached.

Parameters:

  • timeout (Numeric)

    how many time in seconds to wait

  • interval (Numeric)

    time in seconds between attempts



10
11
12
13
14
15
16
17
18
# File 'lib/yui_rest_client/timer.rb', line 10

def wait(timeout, interval)
  return yield if timeout.zero?

  end_time = Time.now.to_f + timeout
  while Time.now.to_f <= end_time
    yield
    sleep interval
  end
end