Sha256: 0e9ec8934277fb73d99f9ec547c1078ca2e21c1b50b86c89049c894749ca2ce4

Contents?: true

Size: 598 Bytes

Versions: 32

Compression:

Stored size: 598 Bytes

Contents

require 'timeout'

class Puppeteer::TimeoutHelper
  # @param timeout_ms [String|Integer|nil]
  # @param default_timeout_ms [Integer]
  def initialize(task_name, timeout_ms:, default_timeout_ms:)
    @task_name = task_name
    @timeout_ms = (timeout_ms || default_timeout_ms).to_i
  end

  def with_timeout(&block)
    if @timeout_ms > 0
      begin
        Timeout.timeout(@timeout_ms / 1000.0, &block)
      rescue Timeout::Error
        raise Puppeteer::TimeoutError.new("waiting for #{@task_name} failed: timeout #{@timeout_ms}ms exceeded")
      end
    else
      block.call
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
puppeteer-ruby-0.45.6 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.45.5 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.45.4 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.45.3 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.45.2 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.45.2.alpha2 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.45.2.alpha1 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.45.1 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.45.0 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.44.3 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.44.2 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.44.1 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.44.0 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.43.1 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.43.0 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.42.0 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.41.0 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.40.7 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.40.6 lib/puppeteer/timeout_helper.rb
puppeteer-ruby-0.40.5 lib/puppeteer/timeout_helper.rb