Class: Watir::Wait::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/watir/wait/timer.rb

Instance Method Summary collapse

Constructor Details

#initialize(timeout: nil) ⇒ Timer

Returns a new instance of Timer.


4
5
6
7
# File 'lib/watir/wait/timer.rb', line 4

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

Instance Method Details

#locked?Boolean

Returns:

  • (Boolean)

33
34
35
# File 'lib/watir/wait/timer.rb', line 33

def locked?
  !@end_time.nil?
end

#remaining_timeObject


25
26
27
# File 'lib/watir/wait/timer.rb', line 25

def remaining_time
  @end_time - current_time
end

#reset!Object


29
30
31
# File 'lib/watir/wait/timer.rb', line 29

def reset!
  @end_time = nil
end

#wait(timeout) { ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Executes given block until it returns true or exceeds timeout.

Parameters:

  • timeout (Integer)

Yields:

  • block


16
17
18
19
20
21
22
23
# File 'lib/watir/wait/timer.rb', line 16

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.negative?
  end
end