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
-
#connection(env) {|conn| ... } ⇒ Object
from Faraday::Adapter#connection.
- #enqueue(request) ⇒ Object
-
#initialize(options) ⇒ ParallelManager
constructor
A new instance of ParallelManager.
- #run ⇒ Object
Methods included from RequestMixin
Constructor Details
#initialize(options) ⇒ ParallelManager
Returns a new instance of ParallelManager.
189 190 191 192 |
# File 'lib/httpx/adapters/faraday.rb', line 189 def initialize() @handlers = [] @connection_options = end |
Instance Method Details
#connection(env) {|conn| ... } ⇒ Object
from Faraday::Adapter#connection
226 227 228 229 230 231 |
# File 'lib/httpx/adapters/faraday.rb', line 226 def connection(env) conn = build_connection(env) return conn unless block_given? yield conn end |
#enqueue(request) ⇒ Object
194 195 196 197 198 |
# File 'lib/httpx/adapters/faraday.rb', line 194 def enqueue(request) handler = ResponseHandler.new(request) @handlers << handler handler end |
#run ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/httpx/adapters/faraday.rb', line 200 def run return unless @handlers.last env = @handlers.last.env connect(env) do |session| requests = @handlers.map { |handler| session.build_request(*build_request(handler.env)) } if env.request.stream_response? requests.each do |request| request.response_on_data = env.request.on_data end end 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) if handler.on_complete end end rescue ::HTTPX::TimeoutError => e raise Faraday::TimeoutError, e end |