Sha256: 90973afa6a8198a4d339798cdf17a770d96f8a3e93725941ede5309b78151e12

Contents?: true

Size: 838 Bytes

Versions: 40

Compression:

Stored size: 838 Bytes

Contents

module Beaker
  module Shared
    module Repetition

      def repeat_for seconds, &block
        # do not peg CPU if &block takes less than 1 second
        repeat_for_and_wait seconds, 1, &block
      end

      def repeat_for_and_wait seconds, wait, &block
        timeout = Time.now + seconds
        done = false
        until done or timeout < Time.now do
          done = block.call
          sleep wait unless done
        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

40 entries across 40 versions & 1 rubygems

Version Path
beaker-4.38.1 lib/beaker/shared/repetition.rb
beaker-4.38.0 lib/beaker/shared/repetition.rb
beaker-4.37.2 lib/beaker/shared/repetition.rb
beaker-4.37.1 lib/beaker/shared/repetition.rb
beaker-4.37.0 lib/beaker/shared/repetition.rb
beaker-4.36.1 lib/beaker/shared/repetition.rb
beaker-4.36.0 lib/beaker/shared/repetition.rb
beaker-4.35.0 lib/beaker/shared/repetition.rb
beaker-4.34.0 lib/beaker/shared/repetition.rb
beaker-4.33.0 lib/beaker/shared/repetition.rb
beaker-4.32.0 lib/beaker/shared/repetition.rb
beaker-4.31.0 lib/beaker/shared/repetition.rb
beaker-4.30.0 lib/beaker/shared/repetition.rb
beaker-4.29.1 lib/beaker/shared/repetition.rb
beaker-4.29.0 lib/beaker/shared/repetition.rb
beaker-4.28.1 lib/beaker/shared/repetition.rb
beaker-4.28.0 lib/beaker/shared/repetition.rb
beaker-4.27.1 lib/beaker/shared/repetition.rb
beaker-4.27.0 lib/beaker/shared/repetition.rb
beaker-4.26.0 lib/beaker/shared/repetition.rb