Sha256: d7fca8be3bd6d757d9f7462f1c21685010170201eaf9743148af1f7234e20820

Contents?: true

Size: 635 Bytes

Versions: 2

Compression:

Stored size: 635 Bytes

Contents

module Beaker
  module Shared
    module Repetition

      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

      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 unless done
          last_wait, wait = wait, last_wait + wait
        end
        return done
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
beaker-4.11.0 lib/beaker/shared/repetition.rb
beaker-4.10.0 lib/beaker/shared/repetition.rb