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.



6
7
8
9
# File 'lib/watir/wait/timer.rb', line 6

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

Instance Method Details

#locked?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/watir/wait/timer.rb', line 35

def locked?
  !@end_time.nil?
end

#remaining_timeObject



27
28
29
# File 'lib/watir/wait/timer.rb', line 27

def remaining_time
  @end_time - current_time
end

#reset!Object



31
32
33
# File 'lib/watir/wait/timer.rb', line 31

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



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

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