Sha256: da7b7494a3fa7de51e26d7fb4d6721d95eade8fe8b42f93bd17c64cc71507452

Contents?: true

Size: 485 Bytes

Versions: 5

Compression:

Stored size: 485 Bytes

Contents

module RAutomation
  module WaitHelper
    extend self
    
    class TimeoutError < StandardError
    end

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

5 entries across 5 versions & 1 rubygems

Version Path
rautomation-0.1.0 lib/rautomation/wait_helper.rb
rautomation-0.0.4 lib/rautomation/wait_helper.rb
rautomation-0.0.3 lib/rautomation/wait_helper.rb
rautomation-0.0.2 lib/rautomation/wait_helper.rb
rautomation-0.0.1 lib/rautomation/wait_helper.rb