Class: Faraday::Adapter::HTTPX::ParallelManager
- Inherits:
-
Object
- Object
- Faraday::Adapter::HTTPX::ParallelManager
- Includes:
- RequestMixin
- Defined in:
- lib/httpx/adapters/faraday.rb
Defined Under Namespace
Classes: ResponseHandler
Instance Method Summary collapse
- #enqueue(request) ⇒ Object
-
#initialize ⇒ ParallelManager
constructor
A new instance of ParallelManager.
- #run ⇒ Object
Constructor Details
#initialize ⇒ ParallelManager
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 |
#run ⇒ Object
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 = { uri: env.request.proxy } session = @session.with((env)) session = session.plugin(:proxy).with_proxy() 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 |