twilio-transport
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -167,2 +167,4 @@ 'use strict'; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
_classCallCheck(this, Transport); | ||
@@ -176,3 +178,7 @@ | ||
return _this2._twilsock && _this2._twilsock.isConnected; | ||
} } | ||
} }, | ||
_concurrentHttpRequestLimit: { value: options.concurrentHttpRequestLimit || Infinity }, | ||
_concurrentHttpRequestCount: { value: 0, writable: true }, | ||
_requestQueue: { value: [] } | ||
}); | ||
@@ -182,2 +188,5 @@ | ||
twilsock.connect(); | ||
twilsock.on('connected', function () { | ||
return _this2._processQueuedRequests(); | ||
}); | ||
} | ||
@@ -233,4 +242,20 @@ } | ||
return sendViaTwilsock(); | ||
} else if (forceTwilsock) { | ||
return Promise.reject(new TwilsockUnavailableError()); | ||
} else if (_this4._concurrentHttpRequestCount >= _this4._concurrentHttpRequestLimit) { | ||
return new Promise(function (resolve, reject) { | ||
return _this4._requestQueue.push({ sendingOptions: sendingOptions, resolve: resolve, reject: reject }); | ||
}); | ||
} | ||
return !forceTwilsock ? sendDirectHttp() : Promise.reject(new TwilsockUnavailableError()); | ||
_this4._concurrentHttpRequestCount++; | ||
return sendDirectHttp().then(function (r) { | ||
_this4._concurrentHttpRequestCount--; | ||
_this4._processQueuedRequests(); | ||
return r; | ||
}).catch(function (err) { | ||
_this4._concurrentHttpRequestCount--; | ||
_this4._processQueuedRequests(); | ||
throw err; | ||
}); | ||
}; | ||
@@ -246,2 +271,16 @@ | ||
}, { | ||
key: '_processQueuedRequests', | ||
value: function _processQueuedRequests() { | ||
while (this._requestQueue.length > 0 && (this._twilsockIsAvailable || this._concurrentHttpRequestCount < this._concurrentHttpRequestLimit)) { | ||
var r = this._requestQueue.shift(); | ||
this._oneOfBasedOnChannelAvailability(r.sendingOptions, false).then(r.resolve).catch(r.reject); | ||
} | ||
} | ||
/** | ||
* @private | ||
*/ | ||
}, { | ||
key: '_get', | ||
@@ -248,0 +287,0 @@ value: function _get(uri, headers, forceTwilsock) { |
{ | ||
"name": "twilio-transport", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Twilio generic transport interface", | ||
@@ -5,0 +5,0 @@ "main": "lib/transport.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52215
902