module Beaker::Shared::Repetition

Public Instance Methods

repeat_fibonacci_style_for(attempts) { || ... } click to toggle source
# File lib/beaker/shared/repetition.rb, line 19
def repeat_fibonacci_style_for attempts
  done = false
  attempt = 1
  last_wait, wait = 0, 1
  while not done and attempt <= attempts
    done = yield
    attempt += 1
    sleep wait unless done
    last_wait, wait = wait, last_wait + wait
  end
  return done
end
repeat_for(seconds, &block) click to toggle source
# File lib/beaker/shared/repetition.rb, line 4
def repeat_for seconds, &block
  # do not peg CPU if &block takes less than 1 second
  repeat_for_and_wait seconds, 1, &block
end
repeat_for_and_wait(seconds, wait) { || ... } click to toggle source
# File lib/beaker/shared/repetition.rb, line 9
def repeat_for_and_wait seconds, wait
  timeout = Time.now + seconds
  done = false
  until done or timeout < Time.now
    done = yield
    sleep wait unless done
  end
  return done
end