class HTTPX::Selector

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

Public Class methods

new()
[show source]
   # File lib/httpx/selector.rb
19 def initialize
20   @timers = Timers.new
21   @selectables = []
22   @is_timer_interval = false
23 end

Public Instance methods

deregister(io)

deregisters io from selectables.

[show source]
    # File lib/httpx/selector.rb
101 def deregister(io)
102   @selectables.delete(io)
103 end
each(&blk)
[show source]
   # File lib/httpx/selector.rb
25 def each(&blk)
26   @selectables.each(&blk)
27 end
each_connection(&block)
[show source]
   # File lib/httpx/selector.rb
76 def each_connection(&block)
77   return enum_for(__method__) unless block
78 
79   @selectables.each do |c|
80     if c.is_a?(Resolver::Resolver)
81       c.each_connection(&block)
82     else
83       yield c
84     end
85   end
86 end
find_connection(request_uri, options)
[show source]
   # File lib/httpx/selector.rb
88 def find_connection(request_uri, options)
89   each_connection.find do |connection|
90     connection.match?(request_uri, options)
91   end
92 end
find_mergeable_connection(connection)
[show source]
   # File lib/httpx/selector.rb
94 def find_mergeable_connection(connection)
95   each_connection.find do |ch|
96     ch != connection && ch.mergeable?(connection)
97   end
98 end
find_resolver(options)
[show source]
   # File lib/httpx/selector.rb
68 def find_resolver(options)
69   res = @selectables.find do |c|
70     c.is_a?(Resolver::Resolver) && options == c.options
71   end
72 
73   res.multi if res
74 end
next_tick()
[show source]
   # File lib/httpx/selector.rb
29 def next_tick
30   catch(:jump_tick) do
31     timeout = next_timeout
32     if timeout && timeout.negative?
33       @timers.fire
34       throw(:jump_tick)
35     end
36 
37     begin
38       select(timeout, &:call)
39       @timers.fire
40     rescue TimeoutError => e
41       @timers.fire(e)
42     end
43   end
44 rescue StandardError => e
45   emit_error(e)
46 rescue Exception # rubocop:disable Lint/RescueException
47   each_connection do |conn|
48     conn.force_reset
49     conn.disconnect
50   end
51 
52   raise
53 end
register(io)

register io.

[show source]
    # File lib/httpx/selector.rb
106 def register(io)
107   return if @selectables.include?(io)
108 
109   @selectables << io
110 end
terminate()
[show source]
   # File lib/httpx/selector.rb
55 def terminate
56   # array may change during iteration
57   selectables = @selectables.reject(&:inflight?)
58 
59   selectables.each(&:terminate)
60 
61   until selectables.empty?
62     next_tick
63 
64     selectables &= @selectables
65   end
66 end