Socket
Socket
Sign inDemoInstall

leaky-bucket

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaky-bucket - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

40

lib/LeakyBucket.js
(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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc