Methods
Public Class
Public Instance
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 112 def deregister(io) 113 @selectables.delete(io) 114 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 86 def each_connection(&block) 87 return enum_for(__method__) unless block 88 89 @selectables.each do |c| 90 case c 91 when Resolver::Resolver 92 c.each_connection(&block) 93 when Connection 94 yield c 95 end 96 end 97 end
find_connection(request_uri, options)
[show source]
# File lib/httpx/selector.rb 99 def find_connection(request_uri, options) 100 each_connection.find do |connection| 101 connection.match?(request_uri, options) 102 end 103 end
find_mergeable_connection(connection)
[show source]
# File lib/httpx/selector.rb 105 def find_mergeable_connection(connection) 106 each_connection.find do |ch| 107 ch != connection && ch.mergeable?(connection) 108 end 109 end
find_resolver(options)
[show source]
# File lib/httpx/selector.rb 78 def find_resolver(options) 79 res = @selectables.find do |c| 80 c.is_a?(Resolver::Resolver) && options == c.options 81 end 82 83 res.multi if res 84 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) do |c| 39 c.log(level: 2) { "[#{c.state}] selected#{" after #{timeout} secs" unless timeout.nil?}..." } 40 41 c.call 42 end 43 44 @timers.fire 45 rescue TimeoutError => e 46 @timers.fire(e) 47 end 48 end 49 rescue StandardError => e 50 each_connection do |c| 51 c.emit(:error, e) 52 end 53 rescue Exception # rubocop:disable Lint/RescueException 54 each_connection do |conn| 55 conn.force_reset 56 conn.disconnect 57 end 58 59 raise 60 end
register(io)
register io
.
[show source]
# File lib/httpx/selector.rb 117 def register(io) 118 return if @selectables.include?(io) 119 120 @selectables << io 121 end
terminate()
[show source]
# File lib/httpx/selector.rb 62 def terminate 63 # array may change during iteration 64 selectables = @selectables.reject(&:inflight?) 65 66 selectables.delete_if do |sel| 67 sel.terminate 68 sel.state == :closed 69 end 70 71 until selectables.empty? 72 next_tick 73 74 selectables &= @selectables 75 end 76 end