Cole-Greer commented on code in PR #3395:
URL: https://github.com/apache/tinkerpop/pull/3395#discussion_r3171041612


##########
gremlin-js/gremlin-javascript/lib/driver/connection.ts:
##########
@@ -115,20 +113,87 @@ export default class Connection extends EventEmitter {
     return Promise.resolve();
   }
 
-  /** @override */
-  submit(request: RequestMessage) {
-    // The user may not want the body to be serialized if they are using an 
interceptor.
+  /**
+   * Send a request and buffer the entire response. Returns a 
Promise<ResultSet>.
+   */
+  async submit(request: RequestMessage) {
     const body = this._writer ? this._writer.writeRequest(request) : request;
-    
-    return this.#makeHttpRequest(body)
-        .then((response) => {
-          return this.#handleResponse(response);
-        });
+    const response = await this.#makeHttpRequest(body);
+    return this.#handleResponse(response);
   }
 
-  /** @override */
-  stream(request: RequestMessage): Readable {
-    throw new Error('stream() is not yet implemented');
+  /**
+   * Send a request and stream the response incrementally.
+   * Returns an AsyncGenerator that yields deserialized result items.
+   * For bulked responses, yields Traverser objects.
+   *
+   * In the GraphBinary v4 streaming protocol, the server sends the status 
after all
+   * result data. If the server encounters an error mid-traversal, values 
yielded before
+   * the error are valid partial results. A ResponseError is thrown after the 
last value
+   * has been yielded.
+   *
+   * @param {RequestMessage} request
+   * @returns {AsyncGenerator<any>}
+   */
+  async *stream(request: RequestMessage): AsyncGenerator<any> {
+    const body = this._writer ? this._writer.writeRequest(request) : request;
+    const abortController = new AbortController();
+
+    let response: Response;
+    try {
+      response = await this.#makeHttpRequest(body, abortController.signal);
+    } catch (e: any) {
+      throw new Error(`Stream request failed: ${e.message}`, { cause: e });
+    }
+
+    if (!response.ok) {
+      // For error responses, buffer and parse the error body
+      const buffer = Buffer.from(await response.arrayBuffer());
+      const errorMessage = `Server returned HTTP ${response.status}: 
${response.statusText}`;
+      const reader = 
this.#getReaderForContentType(response.headers.get("Content-Type"));
+
+      if (reader) {
+        try {
+          const deserialized = await reader.readResponse(buffer);
+          const attributes = new Map();
+          if (deserialized.status.exception) {

Review Comment:
   I've updated to the correct format.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to