Sha256: dee37c9d56f50534c944d79f00100571fd07edbdf9c2b8d031aef5629b5377eb

Contents?: true

Size: 587 Bytes

Versions: 13

Compression:

Stored size: 587 Bytes

Contents

module Mirage

  class TimeoutException < Exception
  end


  # module WaitMethods - contains methods for waiting
  module WaitMethods
    # Wait until a the supplied block returns true
    # @example
    #   wait_until do
    #     (rand % 2) == 0
    #   end
    def wait_until(opts = {})
      opts = {timeout_after: 5, retry_every: 0.1}.merge(opts)
      start_time = Time.now
      until Time.now > start_time + opts[:timeout_after]
        return true if yield == true
        sleep opts[:retry_every]
      end
      fail TimeoutException, 'Action took to long'
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mirage-4.0.0.alpha10 lib/mirage/wait_methods.rb
mirage-4.0.0.alpha9 lib/mirage/wait_methods.rb
mirage-4.0.0.alpha8 lib/mirage/wait_methods.rb
mirage-4.0.0.alpha6 lib/mirage/wait_methods.rb
mirage-4.0.0.alpha5 lib/mirage/wait_methods.rb
mirage-4.0.0.alpha4 lib/mirage/wait_methods.rb
mirage-4.0.0.alpha3 lib/mirage/wait_methods.rb
mirage-4.0.0.alpha2 lib/mirage/wait_methods.rb
mirage-4.0.0.alpha1 lib/mirage/wait_methods.rb
mirage-3.0.14 lib/mirage/wait_methods.rb
mirage-3.0.13 lib/mirage/wait_methods.rb
mirage-3.0.12 lib/mirage/wait_methods.rb
mirage-3.0.11 lib/mirage/wait_methods.rb