leaky-bucket
Advanced tools
Comparing version 2.1.1 to 2.1.2
(function() { | ||
'use strict'; | ||
const Class = require('ee-class'); | ||
@@ -11,3 +11,3 @@ const type = require('ee-types'); | ||
module.exports = new Class({ | ||
@@ -45,4 +45,4 @@ | ||
// indicates how long the next item has to | ||
// wait until its executed, stored as reserved cost, | ||
// indicates how long the next item has to | ||
// wait until its executed, stored as reserved cost, | ||
// not time | ||
@@ -61,4 +61,4 @@ , waitTime: 0 | ||
, init: function(capacity, interval, maxWaitingTime) { | ||
if (type.object(capacity) && capacity !== null) { | ||
if (type.object(capacity)) { | ||
if (type.number(capacity.capacity)) this.capacity = capacity.capacity; | ||
@@ -87,3 +87,3 @@ if (type.number(capacity.interval)) this.slotSize = capacity.interval; | ||
if (debug) log.info('[%s] Created leaky bucket with a capacity of %s, a slot size of %s seconds and a refill rate of %s second per item ...', this.logId, this.capacity, this.slotSize, this.refillRate); | ||
if (debug) log.info('[%s] Created leaky bucket with a capacity of %s, a slot size of %s seconds and a refill rate of %s second per item ...', this.logId, this.capacity, this.slotSize, this.refillRate); | ||
} | ||
@@ -95,3 +95,3 @@ | ||
* throttle a function | ||
* | ||
* | ||
* @param <integer|function> the cost of the operation (defaults to 1) or callback | ||
@@ -101,3 +101,3 @@ * @param <function> optional callback | ||
, throttle: function(cost, cb) { | ||
// check the input | ||
@@ -130,5 +130,5 @@ if (type.function(cost)) { | ||
* in case you dont know the cost of an item in advance | ||
* you may use this method to substract the actual cost | ||
* of the operation after theoperation was executed. | ||
* | ||
* you may use this method to substract the actual cost | ||
* of the operation after theoperation was executed. | ||
* | ||
* @param <integer> the cost to substract | ||
@@ -199,3 +199,3 @@ * | ||
* @param <function> callback | ||
* @param <boolean> optional if the item is a | ||
* @param <boolean> optional if the item is a | ||
* pause item | ||
@@ -245,3 +245,3 @@ */ | ||
for (i = 0; i < this.queue.length; i++) { | ||
// is this item not called in time? | ||
@@ -287,9 +287,9 @@ if ((totalCost+this.queue[i].cost)*this.refillRate > this.maxWaitingTime && i !== 0) { | ||
/** | ||
* private throttle method, works only with callbacks. | ||
* private throttle method, works only with callbacks. | ||
* the public interface works with promises too. | ||
* | ||
* @param <integer> the cost of the operation | ||
* @param <integer> the cost of the operation | ||
* @param <function> callback | ||
* @param <boolean> true if the items source is the queue | ||
* @param <boolean> optional if the item is a | ||
* @param <boolean> optional if the item is a | ||
* pause item | ||
@@ -324,3 +324,3 @@ */ | ||
else { | ||
// we need to compute the time until this item will be executed, | ||
// we need to compute the time until this item will be executed, | ||
// if the timeout time is exceeded don't queue bit return an errror | ||
@@ -360,6 +360,6 @@ waitTime = Math.max((this.waitTime*(1000*this.refillRate)-(now-this.last))/1000, 0); | ||
if (debug) log.debug('[%s] started a timer for the next item to be executed, waiting %s milliseconds ...', this.logId, Math.max(Math.ceil((this.queue[0].cost-this.left)*this.refillRate*1000), 0)); | ||
// start a new timeout | ||
this.timer = setTimeout(function() { | ||
// freee the timer, so it can be re-set | ||
@@ -366,0 +366,0 @@ this.timer = null; |
{ | ||
"name" : "leaky-bucket" | ||
, "description" : "A fast and efficient leaky bucket implementation" | ||
, "version" : "2.1.1" | ||
, "homepage" : "https://github.com/eventEmitter/leaky-bucket" | ||
, "author" : "Michael van der Weg <michael@joinbox.com> (http://joinbox.com/)" | ||
, "license" : "MIT" | ||
, "repository": { | ||
"url" : "https://github.com/eventEmitter/leaky-bucket.git" | ||
, "type" : "git" | ||
"name": "leaky-bucket", | ||
"description": "A fast and efficient leaky bucket implementation", | ||
"version": "2.1.2", | ||
"homepage": "https://github.com/eventEmitter/leaky-bucket", | ||
"author": "Michael van der Weg <michael@joinbox.com> (http://joinbox.com/)", | ||
"license": "MIT", | ||
"repository": { | ||
"url": "https://github.com/eventEmitter/leaky-bucket.git", | ||
"type": "git" | ||
}, | ||
"engines": { | ||
"node": ">=v4.2" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/eventEmitter/leaky-bucket/issues" | ||
}, | ||
"dependencies": { | ||
"ee-argv": "0.1.x", | ||
"ee-class": "1.x", | ||
"ee-log": "^3.0.5", | ||
"ee-types": "^2.1.4" | ||
}, | ||
"devDependencies": { | ||
"mocha": "2.x" | ||
}, | ||
"optionalDependencies": {}, | ||
"keywords": [ | ||
"leaky-bucket", | ||
"leaky", | ||
"bucket" | ||
], | ||
"scripts": { | ||
"test": "./node_modules/mocha/bin/mocha --reporter spec" | ||
} | ||
, "engines": { | ||
"node" : ">=v4.2" | ||
} | ||
, "bugs": { | ||
"url" : "https://github.com/eventEmitter/leaky-bucket/issues" | ||
} | ||
, "dependencies": { | ||
"ee-class" : "1.x" | ||
, "ee-types" : "1.x" | ||
, "ee-log" : "0.3.x" | ||
, "ee-argv" : "0.1.x" | ||
} | ||
, "devDependencies": { | ||
"mocha" : "2.x" | ||
} | ||
, "optionalDependencies": {} | ||
, "keywords" : ["leaky-bucket", "leaky", "bucket"] | ||
, "scripts": { | ||
"test" : "./node_modules/mocha/bin/mocha --reporter spec" | ||
} | ||
} |
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
31040
+ Added@distributed-systems/callsite@1.1.1(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.13.2.1(transitive)
+ Addedapp-root-path@2.2.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedchalk@1.1.32.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedee-log@1.1.03.0.9(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedlogd-console-output@1.3.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedsection-tests@1.3.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.05.5.0(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedee-log@0.3.11(transitive)
- Removedee-types@1.0.0(transitive)
Updatedee-log@^3.0.5
Updatedee-types@^2.1.4