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 end

Public Instance methods

deregister(io)

deregisters io from selectables.

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

register io.

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