tkolanko commented on a change in pull request #1539:
URL: https://github.com/apache/tinkerpop/pull/1539#discussion_r787792222



##########
File path: docs/src/reference/gremlin-variants.asciidoc
##########
@@ -1721,6 +1721,32 @@ IMPORTANT: The preferred method for setting a 
per-request timeout for scripts is
 with bytecode may try `g.with(EVALUATION_TIMEOUT, 500)` within a script. 
Scripts with multiple traversals and multiple
 timeouts will be interpreted as a sum of all timeouts identified in the script 
for that request.
 
+
+==== Processing results as they are returned from the Gremlin server
+
+
+The Gremlin JavaScript driver maintains a WebSocket connection to the Gremlin 
server and receives messages according to the `batchSize` parameter on the per 
request settings or the `resultIterationBatchSize` value configured for the 
Gremlin server. When submitting scripts the default behavior is to wait for the 
entire result set to be returned from a query before allowing any processing on 
the result set. 
+
+The following examples assume that you have 100 vertices in your graph.
+
+[source,javascript]
+----
+const result = await client.submit("g.V()");
+console.log(result.toArray()); // 100 - all the vertices in your graph
+----
+
+When working with larger result sets it may be beneficial for memory 
management to process each chunk of data as it is returned from the gremlin 
server. The Gremlin JavaScript driver can accept an optional callback to run on 
each chunk of data returned.
+
+[source,javascript]
+----
+
+await client.submit("g.V()", {}, { batchSize: 25 }, (data) => {

Review comment:
       Our use case might be different, we don't operate on traverals but 
through submitting scripts. We have a front end user interface where users can 
enter queries with auto complete, intellisense etc etc along with some options. 
The frontend POSTS the query and options to our backend which submits the 
script, parses the result set and returns a result to the frontend.
   
   
   I went with this approach so we could so something like
   ```js
   import {parseResultSet} from './parser';
   
   ...code to handle parsing the POST request and extracting what we need...
   const output = {...} // object that holds our parsed data
   try {
     await client.submit(query, bindings, options, (data) => 
parseResultSet(data, output))
   } catch(e) {
     ...additional error handling/clean up...
    throw new Error(e);
   }
   return res.json(output))
   ```
   
   This seemed like an easier opt in path than trying to handle async iteration 
on websocket messages
   




-- 
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