Sha256: 501df5ce196c7743f0b72524231092a9681944ef54a6f9ec4f05413e59dab9d0

Contents?: true

Size: 804 Bytes

Versions: 16

Compression:

Stored size: 804 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
        timeout = Time.now + seconds
        done = false
        until done or timeout < Time.now
          done = yield
          sleep wait unless done
        end
        return done
      end

      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
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
beaker-6.4.1 lib/beaker/shared/repetition.rb
beaker-6.4.0 lib/beaker/shared/repetition.rb
beaker-6.3.0 lib/beaker/shared/repetition.rb
beaker-6.2.0 lib/beaker/shared/repetition.rb
beaker-6.1.0 lib/beaker/shared/repetition.rb
beaker-5.8.1 lib/beaker/shared/repetition.rb
beaker-5.8.0 lib/beaker/shared/repetition.rb
beaker-5.7.0 lib/beaker/shared/repetition.rb
beaker-5.6.0 lib/beaker/shared/repetition.rb
beaker-5.5.0 lib/beaker/shared/repetition.rb
beaker-5.4.0 lib/beaker/shared/repetition.rb
beaker-5.3.1 lib/beaker/shared/repetition.rb
beaker-5.3.0 lib/beaker/shared/repetition.rb
beaker-5.2.0 lib/beaker/shared/repetition.rb
beaker-5.1.0 lib/beaker/shared/repetition.rb
beaker-5.0.0 lib/beaker/shared/repetition.rb