jbmusso / gremlin-javascript

JavaScript tools for graph processing in Node.js and the browser inspired by the Apache TinkerPop API
MIT License
214 stars 63 forks source link

add client.terminate() #82

Open abdullahshahin opened 7 years ago

abdullahshahin commented 7 years ago

enable the client to close the web socket once they're need it, this method will make sure all commands have been done executing and then it will close the socket

let gremlin = require('gremlin-secure');
const client = gremlin.createClient(
        443,
        "someURL.graphs.azure.com",
        {
            session: false,
            ssl: true,
            user: "/dbs/test/colls/test",
            password: "secretPassword"
        }
        );
for(var i =0; i < 30; i++){
      client.execute('g.V().has("id", id)', { id: 'shahin' }, (err, results) => {
          if (err) {
              return console.error(err)
          }
          console.log(results);
      });
}
client.terminate();
jbmusso commented 7 years ago

I don't think setInterval is the right thing to do here. Could you please share what you had in mind?

abdullahshahin commented 7 years ago

make sure all commands have been executed, once terminate is submitted, there is a chance to have some commands are still being processed and the response is not delivered yet, so am setting the interval to keep checking whether its a good time to end the web socket, I have a use case to insert thousands of entries using async.eachLimit and every time I got 50 transitions, the 50 transactions may not delivered in time. I may realize that this could occupy a cpu power, is there any better way we can handle it differently ?

brianfoody commented 7 years ago

I think my pull request covers this?

https://github.com/jbmusso/gremlin-javascript/pull/81