leaky-bucket
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -139,6 +139,25 @@ (function() { | ||
/** | ||
* returns ifno about the counters fo the bucket | ||
* | ||
* @returns {object} info | ||
*/ | ||
, getInfo: function() { | ||
// refill | ||
this.left += Math.min((Date.now()-this.last)/1000/this.refillRate, this.capacity); | ||
this.last = Date.now(); | ||
return { | ||
left: this.left | ||
, interval: this.slotSize | ||
, capacity: this.capacity | ||
}; | ||
} | ||
/** | ||
@@ -145,0 +164,0 @@ * pause the leaky bucket for n seconds, |
{ | ||
"name" : "leaky-bucket" | ||
, "description" : "A fast and efficient leaky bucket implementation" | ||
, "version" : "2.0.1" | ||
, "version" : "2.1.0" | ||
, "homepage" : "https://github.com/eventEmitter/leaky-bucket" | ||
@@ -6,0 +6,0 @@ , "author" : "Michael van der Weg <michael@joinbox.com> (http://joinbox.com/)" |
@@ -118,2 +118,14 @@ # leaky-bucket | ||
### Getting information from the bucket | ||
By calling the getInfo method the bucket returns information about its internals | ||
bucket.getInfo(); | ||
{ | ||
left: 100 | ||
, interval: 60 | ||
, capacity: 100 | ||
} | ||
## Flags | ||
@@ -120,0 +132,0 @@ |
@@ -385,3 +385,20 @@ | ||
}); | ||
it('should return info about the counters', function() { | ||
var bucket = new LeakyBucket(100, 60, 10); | ||
var info = bucket.getInfo(); | ||
assert.equal(info.left, 100); | ||
assert.equal(info.capacity, 100); | ||
assert.equal(info.interval, 60); | ||
}); | ||
}); | ||
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
31387
515
181