schema-client
Advanced tools
Comparing version 3.0.15 to 3.0.16
@@ -9,2 +9,3 @@ const inherits = require('util').inherits; | ||
const RETRY_TIME = 3000; | ||
const MAX_CONCURRENT = 10; | ||
@@ -20,2 +21,3 @@ const Connection = function(host, port, options, callback) { | ||
this.requestBuffer = []; | ||
this.requested = 0; | ||
@@ -40,4 +42,4 @@ this.host = host; | ||
Connection.prototype.connect = function(callback) { | ||
var proto = this.options.clear ? net : tls; | ||
var timeoutMs = this.options.timeout || DEFAULT_TIMEOUT; | ||
const proto = this.options.clear ? net : tls; | ||
const timeoutMs = this.options.timeout || DEFAULT_TIMEOUT; | ||
@@ -78,4 +80,4 @@ if (!this.connectingTimeout) { | ||
// Copy args to avoid leaking | ||
var args = new Array(arguments.length); | ||
for (var i = 0; i < arguments.length; i++) { | ||
const args = new Array(arguments.length); | ||
for (let i = 0; i < arguments.length; i++) { | ||
args[i] = arguments[i]; | ||
@@ -93,6 +95,17 @@ } | ||
var request = JSON.stringify(args.slice(0, -1)); | ||
this.stream.write(request + '\n'); | ||
this.requestNext(); | ||
}; | ||
Connection.prototype.requestNext = function() { | ||
if (this.requested > MAX_CONCURRENT) { | ||
return; | ||
} | ||
const args = this.requestBuffer[this.requested]; | ||
if (args) { | ||
const request = JSON.stringify(args.slice(0, -1)); | ||
this.stream.write(request + '\n'); | ||
this.requested++; | ||
} | ||
}; | ||
Connection.prototype.receive = function(buffer) { | ||
@@ -104,6 +117,9 @@ // Split buffer data on newline char | ||
var data = this.buffer.join(''); | ||
const data = this.buffer.join(''); | ||
this.buffer = []; | ||
this.receiveResponse(data); | ||
if (this.connected && this.stream) { | ||
this.requestNext(); | ||
} | ||
@@ -123,2 +139,4 @@ j = i + 1; | ||
this.requested--; | ||
if (responder === undefined) { | ||
@@ -175,3 +193,2 @@ return; | ||
if (!this.connected) { | ||
this.stream = null; | ||
return; | ||
@@ -186,3 +203,2 @@ } | ||
this.stream = null; | ||
this.emit('close'); | ||
@@ -207,5 +223,7 @@ if (this.requestBuffer.length > 0) { | ||
} | ||
let hasRequests = this.requestBuffer.length; | ||
while (--hasRequests >= 0) { | ||
this.request.apply(this, this.requestBuffer.shift()); | ||
const requestBuffer = this.requestBuffer; | ||
this.requestBuffer = []; | ||
this.requested = 0; | ||
while (requestBuffer.length) { | ||
this.request.apply(this, requestBuffer.shift()); | ||
} | ||
@@ -212,0 +230,0 @@ }; |
{ | ||
"name": "schema-client", | ||
"version": "3.0.15", | ||
"version": "3.0.16", | ||
"description": "Schema API Client for NodeJS", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
117570
3572
14