Module: Beaker::Shared::Repetition
- Included in:
- Beaker::Shared
- Defined in:
- lib/beaker/shared/repetition.rb
Instance Method Summary collapse
Instance Method Details
#repeat_fibonacci_style_for(attempts, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/beaker/shared/repetition.rb', line 14 def repeat_fibonacci_style_for attempts, &block done = false attempt = 1 last_wait, wait = 0, 1 while not done and attempt <= attempts do done = block.call attempt += 1 sleep wait last_wait, wait = wait, last_wait + wait end return done end |
#repeat_for(seconds, &block) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/beaker/shared/repetition.rb', line 5 def repeat_for seconds, &block timeout = Time.now + seconds done = false until done or timeout < Time.now do done = block.call end return done end |