def poll_request(path, connect_options, request_options, request_timeout, started_at, used)
      result = code = body = headers = nil
      if (connection = @http_client.connections[path]).nil? || Time.now >= connection[:expires_at]
        # Use normal :get request using request balancer for first poll
        result, code, body, headers = rest_request(:get, path, connect_options, request_options.dup, used)
        return [result, code, body, headers] if (Time.now - started_at) >= request_timeout
      end
      if result.nil? && (connection = @http_client.connections[path]) && Time.now < connection[:expires_at]
        begin
          # Continue to poll using same connection until get result, timeout, or hit error
          used[:host] = connection[:host]
          result, code, body, headers = @http_client.poll(connection, request_options, started_at + request_timeout)
        rescue HttpException, RestClient::Exception => e
          raise NotResponding.new(e.http_body, e) if RETRY_STATUS_CODES.include?(e.http_code)
          raise NotResponding.new("Request timeout", e) if e.is_a?(RestClient::RequestTimeout)
          raise
        end
      end
      [result, code, body, headers]
    end
def poll_request(path, connect_options, request_options, request_timeout, started_at, used)
      result = code = body = headers = nil
      if (connection = @http_client.connections[path]).nil? || Time.now >= connection[:expires_at]
        # Use normal :get request using request balancer for first poll
        result, code, body, headers = rest_request(:get, path, connect_options, request_options.dup, used)
        return [result, code, body, headers] if (Time.now - started_at) >= request_timeout
      end
      if result.nil? && (connection = @http_client.connections[path]) && Time.now < connection[:expires_at]
        begin
          # Continue to poll using same connection until get result, timeout, or hit error
          used[:host] = connection[:host]
          result, code, body, headers = @http_client.poll(connection, request_options, started_at + request_timeout)
        rescue HttpException, RestClient::Exception => e
          raise NotResponding.new(e.http_body, e) if RETRY_STATUS_CODES.include?(e.http_code)
          raise NotResponding.new("Request timeout", e) if e.is_a?(RestClient::RequestTimeout)
          raise
        end
      end
      [result, code, body, headers]
    end
Make long-polling request

 @param [String] path in URI for desired resource
 @param [Hash] connect_options for HTTP connection
 @param [Hash] request_options for HTTP request
 @param [Integer] request_timeout for a non-nil result
 @param [Time] started_at time for request
 @param [Hash] used container for returning :host used for request;
   needed so that can return it even when the request fails with an exception

 @return [Array] result to be returned followed by response code, body, and headers

 @raise [NotResponding] server not responding, recommend retry
 @raise [HttpException] HTTP failure with associated status code