Sha256: ea0786c4665620dc8fdb02fc69be7066e8f0560e4657e829a337ffc39a1a5d15

Contents?: true

Size: 513 Bytes

Versions: 3

Compression:

Stored size: 513 Bytes

Contents

module RAutomation
  # Waiting with timeout
  module WaitHelper
    extend self
    
    class TimeoutError < StandardError
    end

    # @private
    # Wait until the block evaluates to true or times out.
    def wait_until(timeout = 60, &block)
      end_time = ::Time.now + timeout

      until ::Time.now > end_time
        result = yield(self)
        return result if result
        sleep 0.5
      end

      raise TimeoutError, "timed out after #{timeout} seconds"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rautomation-0.3.0 lib/rautomation/wait_helper.rb
rautomation-0.2.1 lib/rautomation/wait_helper.rb
rautomation-0.2.0 lib/rautomation/wait_helper.rb