Class: HTTPX::Selector

Inherits:
Object
  • Object
show all
Defined in:
lib/httpx/selector.rb

Instance Method Summary collapse

Constructor Details

#initializeSelector

Returns a new instance of Selector.



14
15
16
# File 'lib/httpx/selector.rb', line 14

def initialize
  @selectables = []
end

Instance Method Details

#deregister(io) ⇒ Object

deregisters io from selectables.



19
20
21
# File 'lib/httpx/selector.rb', line 19

def deregister(io)
  @selectables.delete(io)
end

#register(io) ⇒ Object

register io.



24
25
26
27
28
# File 'lib/httpx/selector.rb', line 24

def register(io)
  return if @selectables.include?(io)

  @selectables << io
end

#select(interval, &block) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/httpx/selector.rb', line 126

def select(interval, &block)
  # do not cause an infinite loop here.
  #
  # this may happen if timeout calculation actually triggered an error which causes
  # the connections to be reaped (such as the total timeout error) before #select
  # gets called.
  return if interval.nil? && @selectables.empty?

  return select_one(interval, &block) if @selectables.size == 1

  select_many(interval, &block)
end