lostisland/faraday

Faraday Adapter Parallel Requests On Multiple Domains / Connections

Open

#805 aperta il 12 giu 2018

Vedi su GitHub
 (5 commenti) (0 reazioni) (0 assegnatari)Ruby (997 fork)batch import
featurehelp wanted

Metriche repository

Star
 (5861 star)
Metriche merge PR
 (Merge medio 53m) (3 PR mergiate in 30 g)

Descrizione

Looking at Faraday's wiki page on parallel requests it looks like we can easily handle parallelization for a single connection:

conn = Faraday.new(:url => "http://coolness.com") do |faraday|
  faraday.adapter :typhoeus
end

conn.in_parallel do
  response1 = conn.get('/one')
  response2 = conn.get('/two')
end

But if I wanted to have parallel requests between multiple domains / connections, it seems like the Typhoeus Faraday adapter does not support this. To be more clear, I'm expecting something like this:

conn1 = Faraday.new(:url => "http://coolness.com") do |faraday|
  faraday.adapter :typhoeus
end

conn2 = Faraday.new(:url => "http://hotness.com") do |faraday|
  faraday.adapter :typhoeus
end

manager = Faraday::ParallelManager.new # this does not exist of course...
manager.in_parallel do
  response1 = conn1.get('/one')
  response2 = conn2.get('/two')
end

Is this a planned feature for the future? Or maybe with advanced usage is it possible to pass around the Typhoeus managers into the different connections? Like:

manager = Typhoeus::Hydra.new

conn1.in_parallel(manager) do 
  response1 = conn1.get('/one')
end

conn2.in_parallel(manager) do 
  response2 = conn2.get('/two')
end

Thanks in advance!

Guida contributor