class HTTPX::Pool

  1. lib/httpx/pool.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. close
  2. empty?
  3. find_connection
  4. init_connection
  5. next_tick

Public Class methods

new ()
[show source]
   # File lib/httpx/pool.rb
15 def initialize
16   @resolvers = {}
17   @_resolver_monitors = {}
18   @timers = Timers::Group.new
19   @selector = Selector.new
20   @connections = []
21   @connected_connections = 0
22 end

Public Instance methods

close (connections = @connections)
[show source]
   # File lib/httpx/pool.rb
42 def close(connections = @connections)
43   @timers.cancel
44   connections = connections.reject(&:inflight?)
45   connections.each(&:close)
46   next_tick until connections.none? { |c| @connections.include?(c) }
47   @resolvers.each_value do |resolver|
48     resolver.close unless resolver.closed?
49   end if @connections.empty?
50 end
empty? ()
[show source]
   # File lib/httpx/pool.rb
24 def empty?
25   @connections.empty?
26 end
find_connection (uri, options)

opens a connection to the IP reachable through uri. Many hostnames are reachable through the same IP, so we try to maximize pipelining by opening as few connections as possible.

[show source]
   # File lib/httpx/pool.rb
68 def find_connection(uri, options)
69   @connections.find do |connection|
70     connection.match?(uri, options)
71   end
72 end
init_connection (connection, _options)
[show source]
   # File lib/httpx/pool.rb
52 def init_connection(connection, _options)
53   resolve_connection(connection)
54   connection.on(:open) do
55     @connected_connections += 1
56   end
57   connection.on(:unreachable) do
58     resolver = find_resolver_for(connection)
59     resolver.uncache(connection) if resolver
60     resolve_connection(connection)
61   end
62 end
next_tick ()
[show source]
   # File lib/httpx/pool.rb
28 def next_tick
29   catch(:jump_tick) do
30     @selector.select(next_timeout || @timers.wait_interval) do |monitor|
31       monitor.io.call
32       monitor.interests = monitor.io.interests
33     end
34     @timers.fire
35   end
36 rescue StandardError => ex
37   @connections.each do |connection|
38     connection.emit(:error, ex)
39   end
40 end