Class: HTTPX::Selector
- Inherits:
-
Object
- Object
- HTTPX::Selector
- Extended by:
- Forwardable
- Defined in:
- lib/httpx/selector.rb
Instance Method Summary collapse
-
#deregister(io) ⇒ Object
deregisters
io
from selectables. - #each(&blk) ⇒ Object
- #each_connection(&block) ⇒ Object
- #find_connection(request_uri, options) ⇒ Object
- #find_mergeable_connection(connection) ⇒ Object
- #find_resolver(options) ⇒ Object
-
#initialize ⇒ Selector
constructor
A new instance of Selector.
- #next_tick ⇒ Object
-
#register(io) ⇒ Object
register
io
. - #terminate ⇒ Object
Constructor Details
#initialize ⇒ Selector
Returns a new instance of Selector.
19 20 21 22 23 |
# File 'lib/httpx/selector.rb', line 19 def initialize @timers = Timers.new @selectables = [] @is_timer_interval = false end |
Instance Method Details
#deregister(io) ⇒ Object
deregisters io
from selectables.
101 102 103 |
# File 'lib/httpx/selector.rb', line 101 def deregister(io) @selectables.delete(io) end |
#each(&blk) ⇒ Object
25 26 27 |
# File 'lib/httpx/selector.rb', line 25 def each(&blk) @selectables.each(&blk) end |
#each_connection(&block) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/httpx/selector.rb', line 76 def each_connection(&block) return enum_for(__method__) unless block @selectables.each do |c| if c.is_a?(Resolver::Resolver) c.each_connection(&block) else yield c end end end |
#find_connection(request_uri, options) ⇒ Object
88 89 90 91 92 |
# File 'lib/httpx/selector.rb', line 88 def find_connection(request_uri, ) each_connection.find do |connection| connection.match?(request_uri, ) end end |
#find_mergeable_connection(connection) ⇒ Object
94 95 96 97 98 |
# File 'lib/httpx/selector.rb', line 94 def find_mergeable_connection(connection) each_connection.find do |ch| ch != connection && ch.mergeable?(connection) end end |
#find_resolver(options) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/httpx/selector.rb', line 68 def find_resolver() res = @selectables.find do |c| c.is_a?(Resolver::Resolver) && == c. end res.multi if res end |
#next_tick ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/httpx/selector.rb', line 29 def next_tick catch(:jump_tick) do timeout = next_timeout if timeout && timeout.negative? @timers.fire throw(:jump_tick) end begin select(timeout, &:call) @timers.fire rescue TimeoutError => e @timers.fire(e) end end rescue StandardError => e emit_error(e) rescue Exception # rubocop:disable Lint/RescueException each_connection do |conn| conn.force_reset conn.disconnect end raise end |
#register(io) ⇒ Object
register io
.
106 107 108 109 110 |
# File 'lib/httpx/selector.rb', line 106 def register(io) return if @selectables.include?(io) @selectables << io end |
#terminate ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/httpx/selector.rb', line 55 def terminate # array may change during iteration selectables = @selectables.reject(&:inflight?) selectables.each(&:terminate) until selectables.empty? next_tick selectables &= @selectables end end |