Sha256: 86830605579bdaf5c168b4d53ae4579a057b7ba7840226e973a1671534b946b8

Contents?: true

Size: 623 Bytes

Versions: 163

Compression:

Stored size: 623 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
          last_wait, wait = wait, last_wait + wait
        end
        return done
      end
    end
  end
end

Version data entries

163 entries across 163 versions & 1 rubygems

Version Path
beaker-4.9.0 lib/beaker/shared/repetition.rb
beaker-4.8.0 lib/beaker/shared/repetition.rb
beaker-4.7.0 lib/beaker/shared/repetition.rb
beaker-4.6.0 lib/beaker/shared/repetition.rb
beaker-4.5.0 lib/beaker/shared/repetition.rb
beaker-4.4.0 lib/beaker/shared/repetition.rb
beaker-4.3.0 lib/beaker/shared/repetition.rb
beaker-4.2.0 lib/beaker/shared/repetition.rb
beaker-4.1.0 lib/beaker/shared/repetition.rb
beaker-4.0.0 lib/beaker/shared/repetition.rb
beaker-3.37.0 lib/beaker/shared/repetition.rb
beaker-3.36.0 lib/beaker/shared/repetition.rb
beaker-3.35.0 lib/beaker/shared/repetition.rb
beaker-3.34.0 lib/beaker/shared/repetition.rb
beaker-3.33.0 lib/beaker/shared/repetition.rb
beaker-3.32.0 lib/beaker/shared/repetition.rb
beaker-3.31.0 lib/beaker/shared/repetition.rb
beaker-3.30.0 lib/beaker/shared/repetition.rb
beaker-3.29.0 lib/beaker/shared/repetition.rb
beaker-3.28.0 lib/beaker/shared/repetition.rb