Sha256: 228d99393dd4e3f5b0bb5bffd198cd264dcf31820804bd5d357e94217961eadd

Contents?: true

Size: 1010 Bytes

Versions: 5

Compression:

Stored size: 1010 Bytes

Contents

# frozen_string_literal: true

module Wayfarer
  module Networking
    class Pool
      include Singleton

      cattr_accessor :registry, default: { http: HTTP,
                                           ferrum: Ferrum,
                                           selenium: Selenium,
                                           capybara: Capybara }

      def pool
        @pool ||= ConnectionPool.new(size: Wayfarer.config.network.pool_size,
                                     timeout: Wayfarer.config.network.pool_timeout,
                                     &method(:context))
      end

      def with(&block)
        pool.with(&block)
      rescue ConnectionPool::TimeoutError => e
        raise Wayfarer::UserAgentTimeoutError, e
      end

      def free
        pool.shutdown(&:renew)
      end

    private

      def context
        Wayfarer::Networking::Context.new(strategy)
      end

      def strategy
        self.class.registry[Wayfarer.config.network.agent].new
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wayfarer-0.4.6 lib/wayfarer/networking/pool.rb
wayfarer-0.4.5 lib/wayfarer/networking/pool.rb
wayfarer-0.4.4 lib/wayfarer/networking/pool.rb
wayfarer-0.4.3 lib/wayfarer/networking/pool.rb
wayfarer-0.4.2 lib/wayfarer/networking/pool.rb