lostisland/faraday

Faraday Adapter Parallel Requests On Multiple Domains / Connections

Open

#805 创建于 2018年6月12日

在 GitHub 查看
 (5 评论) (0 反应) (0 负责人)Ruby (5,861 star) (997 fork)batch import
featurehelp wanted

描述

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!

贡献者指南