lib/httpx/session.rb in httpx-0.4.1 vs lib/httpx/session.rb in httpx-0.5.0

- old
+ new

@@ -152,25 +152,25 @@ end def send_requests(*requests, options) connections = [] request_options = @options.merge(options) - timeout = request_options.timeout requests.each do |request| connection = find_connection(request, connections, request_options) connection.send(request) + set_request_timeout(connection, request, request_options) end responses = [] begin # guarantee ordered responses loop do begin request = requests.first - pool.next_tick(timeout) until (response = fetch_response(request, connections, request_options)) + pool.next_tick until (response = fetch_response(request, connections, request_options)) responses << response requests.shift break if requests.empty? || pool.empty? @@ -186,9 +186,24 @@ rklass = @options.request_class request = rklass.new(verb, uri, @options.merge(options)) request.on(:response, &method(:on_response).curry[request]) request.on(:promise, &method(:on_promise)) request + end + + def set_request_timeout(connection, request, options) + total = options.timeout.total_timeout + return unless total + + timer = pool.after(total) do + unless @responses[request] + error = TotalTimeoutError.new(total, "Timed out after #{total} seconds") + response = ErrorResponse.new(request, error, options) + request.emit(:response, response) + connection.reset + end + end + request.timer = timer end @default_options = Options.new @default_options.freeze @plugins = []