diff --git a/src/GremlinClient.js b/src/GremlinClient.js index ca4d885..e6009a9 100644 --- a/src/GremlinClient.js +++ b/src/GremlinClient.js @@ -388,6 +388,22 @@ class GremlinClient extends EventEmitter { return awaitable; } + + /** + * Terminate WebSocket Connection after make sure all commands have been + * Executed Successfully. + */ + terminate() { + let commands = this.commands; + let connection = this.connection; + setInterval(function(){ + if(Object.keys(commands).length === 0) { + this.connected = false; + connection.terminate(); + clearInterval(this); + } + }, 100); + } } export default GremlinClient; diff --git a/src/WebSocketGremlinConnection.js b/src/WebSocketGremlinConnection.js index add97e8..f097f47 100644 --- a/src/WebSocketGremlinConnection.js +++ b/src/WebSocketGremlinConnection.js @@ -41,6 +41,10 @@ export default class WebSocketGremlinConnection extends EventEmitterĀ { this.emit('close', event); } + terminate() { + this.open = false; + this.ws.close(); + } sendMessage(message) { this.ws.send(message, { mask: true, binary: true }, (err) => { if (err) {