Comparing version 0.0.2 to 1.0.0
@@ -59,4 +59,6 @@ | ||
removeTokens: function(count, callback) { | ||
var self = this; | ||
// Is this an infinite size bucket? | ||
if (!this.maxBurst) { | ||
if (!this.bucketSize) { | ||
callback(null, count, Number.POSITIVE_INFINITY); | ||
@@ -81,11 +83,9 @@ return true; | ||
(count - this.content) * (this.interval / this.tokensPerInterval)); | ||
setTimeout(function() { removeTokens(count, callback); }, waitInterval); | ||
setTimeout(function() { self.removeTokens(count, callback); }, waitInterval); | ||
return false; | ||
} | ||
if (parent) { | ||
var self = this; | ||
if (this.parentBucket) { | ||
// Remove the requested from the parent bucket first | ||
return parent.removeTokens(count, function(err, remainingTokens) { | ||
return this.parentBucket.removeTokens(count, function(err, remainingTokens) { | ||
if (err) { | ||
@@ -106,3 +106,3 @@ callback(err, null); | ||
this.content -= count; | ||
callback(null, self.content); | ||
callback(null, this.content); | ||
return true; | ||
@@ -127,3 +127,3 @@ } | ||
var dripAmount = deltaMS * (this.tokensPerInterval / this.interval); | ||
this.content = Math.min(this.content + dripAmount, maxBurst); | ||
this.content = Math.min(this.content + dripAmount, this.bucketSize); | ||
} | ||
@@ -130,0 +130,0 @@ }; |
{ | ||
"name": "limiter", | ||
"description": "A generic rate limiter for node.js. Useful for API clients, web crawling, or other tasks that need to be throttled", | ||
"version": "0.0.2", | ||
"version": "1.0.0", | ||
"author": "John Hurliman <jhurliman@cull.tv>", | ||
"dependencies": { }, | ||
"devDependencies": { }, | ||
"devDependencies": { | ||
"assert": "0.4.9", | ||
"vows": "0.6.3" | ||
}, | ||
"keywords": ["rate", "limiting", "throttling"], | ||
@@ -9,0 +12,0 @@ "repository": "git://github.com/jhurliman/node-rate-limiter", |
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
14609
8
242
1
2
1