@d-fischer/rate-limiter
Advanced tools
Comparing version 0.4.4 to 0.4.5
@@ -19,2 +19,3 @@ "use strict"; | ||
return tslib_1.__generator(this, function (_a) { | ||
this._logger.trace('request start'); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
@@ -27,2 +28,4 @@ var reqSpec = { | ||
if (_this._batchRunning || _this._nextBatchTimer) { | ||
_this._logger.trace("request queued batchRunning:" + _this._batchRunning.toString() + " hasNextBatchTimer:" + (!!_this | ||
._nextBatchTimer).toString()); | ||
_this._queue.push(reqSpec); | ||
@@ -44,7 +47,8 @@ } | ||
case 0: | ||
this._logger.trace("runRequestBatch start specs:" + reqSpecs.length); | ||
this._batchRunning = true; | ||
if (this._parameters) { | ||
this._logger.debug("remaining requests: " + this._parameters.remaining); | ||
this._logger.debug("Remaining requests: " + this._parameters.remaining); | ||
} | ||
this._logger.debug("doing " + reqSpecs.length + " requests, new queue length is " + this._queue.length); | ||
this._logger.debug("Doing " + reqSpecs.length + " requests, new queue length is " + this._queue.length); | ||
promises = reqSpecs.map(function (reqSpec) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
@@ -88,5 +92,6 @@ var req, resolve, reject, result, retry, params, e_1; | ||
if (rejectedPromises.length) { | ||
this._logger.trace('runRequestBatch some rejected'); | ||
retryAt = Math.max.apply(Math, tslib_1.__spread([now], rejectedPromises.map(function (p) { return p.reason.retryAt; }))); | ||
retryAfter = retryAt - now; | ||
this._logger.warn("waiting for " + retryAfter + " ms because the rate limit was exceeded"); | ||
this._logger.warn("Waiting for " + retryAfter + " ms because the rate limit was exceeded"); | ||
this._nextBatchTimer = setTimeout(function () { | ||
@@ -98,2 +103,3 @@ _this._parameters = undefined; | ||
else { | ||
this._logger.trace('runRequestBatch none rejected'); | ||
params = settledPromises | ||
@@ -115,2 +121,3 @@ .filter(function (p) { | ||
if (params.resetsAt < now || params.remaining > 0) { | ||
this._logger.trace('runRequestBatch canRunMore'); | ||
void this._runNextBatch(); | ||
@@ -120,2 +127,3 @@ } | ||
delay = params.resetsAt - now; | ||
this._logger.trace("runRequestBatch delay:" + delay); | ||
this._logger.warn("Waiting for " + delay + " ms because the rate limit was reached"); | ||
@@ -129,2 +137,3 @@ this._nextBatchTimer = setTimeout(function () { | ||
} | ||
this._logger.trace('runRequestBatch end'); | ||
return [2 /*return*/]; | ||
@@ -139,2 +148,3 @@ } | ||
return tslib_1.__generator(this, function (_a) { | ||
this._logger.trace('runNextBatch start'); | ||
if (this._nextBatchTimer) { | ||
@@ -149,2 +159,3 @@ clearTimeout(this._nextBatchTimer); | ||
} | ||
this._logger.trace('runNextBatch end'); | ||
return [2 /*return*/]; | ||
@@ -151,0 +162,0 @@ }); |
{ | ||
"name": "@d-fischer/rate-limiter", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"description": "Rate limit your requests.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
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
73834
974