Module: Autoscale::Agent::Util

Defined in:
lib/autoscale/agent/util.rb

Class Method Summary collapse

Class Method Details

.loop_with_interval(interval, &block) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/autoscale/agent/util.rb', line 6

def loop_with_interval(interval, &block)
  loop do
    start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    block.call
    duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
    sleep [0, interval - duration].max
  end
end