Without the idiot proof Typhoeus on_complete callbacks, I am looking at the best way to handle responses.
def execute(qty)
requests = []
generate_params(qty).each do |params|
requests << ['POST', 'https://api.blahblah.com/api/v2/search', { json: params }]
end
responses = @httpx.bearer_auth('BLAHBLAH').request(requests, max_concurrent_requests: 25)
ensure
responses = [responses] unless responses.is_a?(Array) # so I can do qty=1
requests.zip(responses).each do |request, response|
process_response(request, response)
end
end
This seems to work, with the caveat that if one request fails none are processed. But to be sure, can I double check and ask if HTTP2 Multiplexing with HTTPX always returns the responses in the right order, so my requests.zip(responses) won't cause any surprises? Thanks!
Yes, order is guaranteed. They're also handled independently, I.e. one failing will not influence the rest (at least with HTTP/2, and of course depending on the server).
Without the idiot proof Typhoeus on_complete callbacks, I am looking at the best way to handle responses.
This seems to work, with the caveat that if one request fails none are processed. But to be sure, can I double check and ask if HTTP2 Multiplexing with HTTPX always returns the responses in the right order, so my requests.zip(responses) won't cause any surprises? Thanks!