def async_request_with_retries response, http_request, retry_delays = nil
response.http_response = Http::Response.new
handle = Object.new
handle.extend AsyncHandle
handle.on_complete do |status|
case status
when :failure
response.error = StandardError.new("failed to contact the service")
response.signal_failure
when :success
populate_error(response)
retry_delays ||= sleep_durations(response)
if should_retry?(response) and !retry_delays.empty?
rebuild_http_request(response)
@http_handler.sleep_with_callback(retry_delays.shift) do
async_request_with_retries(response, response.http_request, retry_delays)
end
else
response.error ?
response.signal_failure :
response.signal_success
end
end
end
@http_handler.handle_async(http_request, response.http_response, handle)
end