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
48 def close(connections = @connections)
49   @timers.cancel
50   connections = connections.reject(&:inflight?)
51   connections.each(&:close)
52   next_tick until connections.none? { |c| @connections.include?(c) }
53   @resolvers.each_value do |resolver|
54     resolver.close unless resolver.closed?
55   end if @connections.empty?
56 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
75 def find_connection(uri, options)
76   @connections.find do |connection|
77     connection.match?(uri, options)
78   end
79 end
init_connection (connection, _options)
[show source]
   # File lib/httpx/pool.rb
58 def init_connection(connection, _options)
59   resolve_connection(connection)
60   connection.timers = @timers
61   connection.on(:open) do
62     @connected_connections += 1
63   end
64   connection.on(:unreachable) do
65     resolver = find_resolver_for(connection)
66     resolver.uncache(connection) if resolver
67     resolve_connection(connection)
68   end
69 end
next_tick ()
[show source]
   # File lib/httpx/pool.rb
28 def next_tick
29   catch(:jump_tick) do
30     timeout = [next_timeout, @timers.wait_interval].compact.min
31     if timeout.negative?
32       @timers.fire
33       throw(:jump_tick)
34     end
35 
36     @selector.select(timeout) do |monitor|
37       monitor.io.call
38       monitor.interests = monitor.io.interests
39     end
40     @timers.fire
41   end
42 rescue StandardError => e
43   @connections.each do |connection|
44     connection.emit(:error, e)
45   end
46 end