Class: Faraday::Adapter::HTTPX::ParallelManager

Inherits:
Object
  • Object
show all
Includes:
RequestMixin
Defined in:
lib/httpx/adapters/faraday.rb

Defined Under Namespace

Classes: ResponseHandler

Instance Method Summary collapse

Constructor Details

#initializeParallelManager

Returns a new instance of ParallelManager.



134
135
136
137
# File 'lib/httpx/adapters/faraday.rb', line 134

def initialize
  @session = Session.new
  @handlers = []
end

Instance Method Details

#enqueue(request) ⇒ Object



139
140
141
142
143
# File 'lib/httpx/adapters/faraday.rb', line 139

def enqueue(request)
  handler = ResponseHandler.new(request)
  @handlers << handler
  handler
end

#runObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/httpx/adapters/faraday.rb', line 145

def run
  requests = @handlers.map { |handler| build_request(handler.env) }
  env = @handlers.last.env

  proxy_options = { uri: env.request.proxy }

  session = @session.with(options_from_env(env))
  session = session.plugin(:proxy).with_proxy(proxy_options) if env.request.proxy

  responses = session.request(requests)
  Array(responses).each_with_index do |response, index|
    handler = @handlers[index]
    handler.on_response.call(response)
    handler.on_complete.call(handler.env)
  end
end