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 1.0.0 to 2.0.0

.jshintrc

52

lib/LeakyBucket.js

@@ -1,12 +0,12 @@

!function() {
(function() {
'use strict';
const Class = require('ee-class');
const type = require('ee-types');
const log = require('ee-log');
const debug = require('ee-argv').has('debug-leaky-bucket') || process.env['debug-leaky-bucket'];
let logId = 0;
var Class = require('ee-class')
, type = require('ee-types')
, log = require('ee-log')
, Promise = (Promise || require('es6-promise').Promise)
, debug = require('ee-argv').has('debug-leaky-bucket') || process.env['debug-leaky-bucket']
, logId = 0;
module.exports = new Class({

@@ -60,3 +60,3 @@

if (type.object(capacity) && capacity != null) {
if (type.object(capacity) && capacity !== null) {
if (type.number(capacity.capacity)) this.capacity = capacity.capacity;

@@ -118,3 +118,29 @@ if (type.number(capacity.interval)) this.slotSize = capacity.interval;

/**
* 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.
*
* @param <integer> the cost to substract
*
* @returns <boolean> false if the bucket is empty
*/
, pay: function(cost) {
this.left -= cost;
return this.left > 0;
}
/**
* pause the leaky bucket for n seconds,

@@ -288,4 +314,4 @@ * this may be used if you are rate limiting something

// increase the wait time variable so we can copute the exact time
// that it will takr to execute the last added item
// increase the wait time variable so we can compute the exact time
// that it will take to execute the last added item
this.waitTime += cost;

@@ -323,2 +349,2 @@

});
}();
})();
{
"name" : "leaky-bucket"
, "description" : "A fast and efficient leaky bucket implementation"
, "version" : "1.0.0"
, "version" : "2.0.0"
, "homepage" : "https://github.com/eventEmitter/leaky-bucket"

@@ -13,3 +13,3 @@ , "author" : "Michael van der Weg <michael@joinbox.com> (http://joinbox.com/)"

, "engines": {
"node" : ">=v0.12"
"node" : ">=v4.2"
}

@@ -20,10 +20,9 @@ , "bugs": {

, "dependencies": {
"ee-class" : "1.0.x"
, "ee-types" : "0.1.x"
"ee-class" : "1.x"
, "ee-types" : "1.x"
, "ee-log" : "0.3.x"
, "ee-argv" : "0.1.x"
, "es6-promise" : "2.0.x"
}
, "devDependencies": {
"mocha" : "1.17.x"
"mocha" : "2.x"
}

@@ -30,0 +29,0 @@ , "optionalDependencies": {}

@@ -111,2 +111,9 @@ # leaky-bucket

### Removing left credits
If you dont know how much an item costs in advance you may remove the cost afterwards using the pay method.
let limitReached = bucket.pay(345);
## Flags

@@ -113,0 +120,0 @@

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