Gremlin-Javascript: Proper Way to Close Driver Remote Connection

423 views
Skip to first unread message

Taylor Riggan

unread,
Apr 15, 2019, 6:44:41 PM4/15/19
to Gremlin-users
All,

I noticed there were some recent changes made to the Gremlin-Javascript GLV regarding how to close a connection that was created using the Driver Remote Connection.  In 3.3.2 and prior, you could just do the following:

const gremlin = require('gremlin');
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const Graph = gremlin.structure.Graph;

dc = new DriverRemoteConnection('wss://graph-db-endpoint:8182');

const graph = new Graph();
const g = graph.traversal().withRemote(dc);

// << do something / traverse graph >>

dc.close();

In this case dc.close() could be called synchronously even though it was using a Promise internally to issue the closure of the websocket.  There was no need to handle any returning Promise, correct?  Looks like there is one case where a Promise could have been returned (if the connection was already closed?), but in most cases this would not return anything.

Starting in 3.3.4, dc.close() returns a Promise regardless of the state of the connection (whether or not this is the first call to close the connection, or a subsequent call after the connection is already closed).  Given this, should we be handling the returned Promise to make sure the connection has completely closed?  It doesn't appear that there is a lot of documentation around this.  I just wanted to validate the thinking here:

await dc.close();

Thanks in advance!

Jorge Bay

unread,
Apr 17, 2019, 11:17:27 AM4/17/19
to Gremlin-users
Hi,
Your think is correct, close() method returns a Promise that should be handled.

Note that DriverRemoteConnection extends RemoteConnection, close() method in the super class is documented to return a Promise.

Cheers,
Jorge

Reply all
Reply to author
Forward
0 new messages