Sha256: a3fb5443d7658b51ed73537a2ea8d4d5e96578cb5ab741f83279a91522392815

Contents?: true

Size: 1.04 KB

Versions: 13

Compression:

Stored size: 1.04 KB

Contents

module Watir
  module Wait
    class Timer

      def initialize(timeout: nil)
        @end_time = current_time + timeout if timeout
        @remaining_time = @end_time - current_time if @end_time
      end

      #
      # Executes given block until it returns true or exceeds timeout.
      # @param [Integer] timeout
      # @yield block
      # @api private
      #

      def wait(timeout, &block)
        end_time = @end_time || current_time + timeout
        loop do
          yield(block)
          @remaining_time = end_time - current_time
          break if @remaining_time < 0
        end
      end

      def remaining_time
        @end_time - current_time
      end

      def reset!
        @end_time = nil
      end

      def locked?
        !@end_time.nil?
      end

      private

      if defined?(Process::CLOCK_MONOTONIC)
        def current_time
          Process.clock_gettime(Process::CLOCK_MONOTONIC)
        end
      else
        def current_time
          ::Time.now.to_f
        end
      end

    end # Timer
  end # Wait
end # Watir

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
watir-6.13.0 lib/watir/wait/timer.rb
watir-6.12.0 lib/watir/wait/timer.rb
watir-6.11.0 lib/watir/wait/timer.rb
watir-6.11.0.beta2 lib/watir/wait/timer.rb
watir-6.11.0.beta1 lib/watir/wait/timer.rb
watir-6.10.3 lib/watir/wait/timer.rb
watir-6.10.2 lib/watir/wait/timer.rb
watir-6.10.0 lib/watir/wait/timer.rb
watir-6.9.1 lib/watir/wait/timer.rb
watir-6.9.0 lib/watir/wait/timer.rb
watir-6.8.4 lib/watir/wait/timer.rb
watir-6.8.3 lib/watir/wait/timer.rb
watir-6.8.2 lib/watir/wait/timer.rb