Class: Puppeteer::Locator::TimeoutController
- Inherits:
-
Object
- Object
- Puppeteer::Locator::TimeoutController
- Defined in:
- lib/puppeteer/locators.rb
Instance Attribute Summary collapse
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
- #check!(cause = nil) ⇒ Object
- #exceeded? ⇒ Boolean
-
#initialize(timeout) ⇒ TimeoutController
constructor
A new instance of TimeoutController.
- #remaining_timeout ⇒ Object
Constructor Details
#initialize(timeout) ⇒ TimeoutController
Returns a new instance of TimeoutController.
15 16 17 18 19 20 21 22 |
# File 'lib/puppeteer/locators.rb', line 15 def initialize(timeout) @timeout = timeout @deadline = nil return if @timeout.nil? || @timeout == 0 @deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + (@timeout / 1000.0) end |
Instance Attribute Details
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
24 25 26 |
# File 'lib/puppeteer/locators.rb', line 24 def timeout @timeout end |
Instance Method Details
#check!(cause = nil) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/puppeteer/locators.rb', line 40 def check!(cause = nil) return unless exceeded? error = Puppeteer::TimeoutError.new("Timed out after waiting #{@timeout}ms") error.cause = cause if cause raise error end |
#exceeded? ⇒ Boolean
34 35 36 37 38 |
# File 'lib/puppeteer/locators.rb', line 34 def exceeded? return false unless @deadline Process.clock_gettime(Process::CLOCK_MONOTONIC) >= @deadline end |
#remaining_timeout ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/puppeteer/locators.rb', line 26 def remaining_timeout return 0 if @timeout == 0 return nil unless @deadline remaining = (@deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)) * 1000.0 remaining.negative? ? 0 : remaining end |