New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bottleneck

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bottleneck - npm Package Compare versions

Comparing version 1.9.0 to 1.9.1

4

bottleneck.js

@@ -24,3 +24,5 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

e = _error;
return Promise;
return typeof Promise !== "undefined" && Promise !== null ? Promise : function() {
throw new Error("Bottleneck: install 'bluebird' or use Node 0.12 or higher for Promise support");
};
}

@@ -27,0 +29,0 @@ })();

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

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){(function(){var Bottleneck,bind=function(fn,me){return function(){return fn.apply(me,arguments)}},slice=[].slice;Bottleneck=function(){var e;Bottleneck.strategy=Bottleneck.prototype.strategy={LEAK:1,OVERFLOW:2,BLOCK:3};Bottleneck.Cluster=Bottleneck.prototype.Cluster=require("./Cluster");Bottleneck.Promise=Bottleneck.prototype.Promise=function(){try{return require("bluebird")}catch(_error){e=_error;return Promise}}();function Bottleneck(maxNb,minTime,highWater,strategy){this.maxNb=maxNb!=null?maxNb:0;this.minTime=minTime!=null?minTime:0;this.highWater=highWater!=null?highWater:0;this.strategy=strategy!=null?strategy:Bottleneck.prototype.strategy.LEAK;this.submit=bind(this.submit,this);this._nextRequest=Date.now();this._nbRunning=0;this._queue=[];this._timeouts=[];this._unblockTime=0;this.penalty=15*this.minTime||5e3;this.interrupt=false;this.reservoir=null;this.limiter=null}Bottleneck.prototype.chain=function(limiter){this.limiter=limiter;return this};Bottleneck.prototype.isBlocked=function(){return this._unblockTime>=Date.now()};Bottleneck.prototype.check=function(){return(this._nbRunning<this.maxNb||this.maxNb<=0)&&this._nextRequest-Date.now()<=0&&(this.reservoir==null||this.reservoir>0)};Bottleneck.prototype._tryToRun=function(){var done,index,next,wait;if((this._nbRunning<this.maxNb||this.maxNb<=0)&&this._queue.length>0&&(this.reservoir==null||this.reservoir>0)){this._nbRunning++;if(this.reservoir!=null){this.reservoir--}wait=Math.max(this._nextRequest-Date.now(),0);this._nextRequest=Date.now()+wait+this.minTime;next=this._queue.shift();done=false;index=-1+this._timeouts.push(setTimeout(function(_this){return function(){var completed;completed=function(){var ref;if(!done){done=true;delete _this._timeouts[index];_this._nbRunning--;_this._tryToRun();if(!_this.interrupt){return(ref=next.cb)!=null?ref.apply({},Array.prototype.slice.call(arguments,0)):void 0}}};if(_this.limiter!=null){return _this.limiter.submit.apply(_this.limiter,Array.prototype.concat.call(next.task,next.args,completed))}else{return next.task.apply({},next.args.concat(completed))}}}(this),wait));return true}else{return false}};Bottleneck.prototype.submit=function(){var args,cb,i,reachedHighWaterMark,task;task=arguments[0],args=3<=arguments.length?slice.call(arguments,1,i=arguments.length-1):(i=1,[]),cb=arguments[i++];reachedHighWaterMark=this.highWater>0&&this._queue.length===this.highWater;if(this.strategy===Bottleneck.prototype.strategy.BLOCK&&(reachedHighWaterMark||this.isBlocked())){this._unblockTime=Date.now()+this.penalty;this._nextRequest=this._unblockTime+this.minTime;this._queue=[];return true}else if(reachedHighWaterMark){if(this.strategy===Bottleneck.prototype.strategy.LEAK){this._queue.shift()}else if(this.strategy===Bottleneck.prototype.strategy.OVERFLOW){return reachedHighWaterMark}}this._queue.push({task:task,args:args,cb:cb});this._tryToRun();return reachedHighWaterMark};Bottleneck.prototype.schedule=function(){var args,task,wrapped;task=arguments[0],args=2<=arguments.length?slice.call(arguments,1):[];wrapped=function(cb){return task.apply({},args).then(function(){var args;args=1<=arguments.length?slice.call(arguments,0):[];return cb.apply({},Array.prototype.concat.call([],null,args))})["catch"](function(){var args;args=1<=arguments.length?slice.call(arguments,0):[];return cb.apply({},Array.prototype.concat.call({},args))})};return new Bottleneck.prototype.Promise(function(_this){return function(resolve,reject){return _this.submit.apply({},Array.prototype.concat.call(wrapped,function(){var args,error;error=arguments[0],args=2<=arguments.length?slice.call(arguments,1):[];return(error!=null?reject:resolve).apply({},args)}))}}(this))};Bottleneck.prototype.changeSettings=function(maxNb,minTime,highWater,strategy){this.maxNb=maxNb!=null?maxNb:this.maxNb;this.minTime=minTime!=null?minTime:this.minTime;this.highWater=highWater!=null?highWater:this.highWater;this.strategy=strategy!=null?strategy:this.strategy;while(this._tryToRun()){}return this};Bottleneck.prototype.changePenalty=function(penalty){this.penalty=penalty!=null?penalty:this.penalty;return this};Bottleneck.prototype.changeReservoir=function(reservoir){this.reservoir=reservoir;while(this._tryToRun()){}return this};Bottleneck.prototype.incrementReservoir=function(incr){if(incr==null){incr=0}this.changeReservoir(this.reservoir+incr);return this};Bottleneck.prototype.stopAll=function(interrupt){var a,i,len,ref;this.interrupt=interrupt!=null?interrupt:this.interrupt;ref=this._timeouts;for(i=0,len=ref.length;i<len;i++){a=ref[i];clearTimeout(a)}this._tryToRun=function(){};this.submit=function(){return false};return this.check=function(){return false}};return Bottleneck}();module.exports=Bottleneck}).call(this)},{"./Cluster":2,bluebird:undefined}],2:[function(require,module,exports){(function(){var Cluster,hasProp={}.hasOwnProperty;Cluster=function(){function Cluster(maxNb,minTime,highWater,strategy){this.maxNb=maxNb;this.minTime=minTime;this.highWater=highWater;this.strategy=strategy;this.limiters={};this.Bottleneck=require("./Bottleneck");this.startAutoCleanup()}Cluster.prototype.key=function(key){var ref;if(key==null){key=""}return(ref=this.limiters[key])!=null?ref:this.limiters[key]=new this.Bottleneck(this.maxNb,this.minTime,this.highWater,this.strategy)};Cluster.prototype.deleteKey=function(key){if(key==null){key=""}return delete this.limiters[key]};Cluster.prototype.all=function(cb){var k,ref,results,v;ref=this.limiters;results=[];for(k in ref){if(!hasProp.call(ref,k))continue;v=ref[k];results.push(cb(v))}return results};Cluster.prototype.keys=function(){return Object.keys(this.limiters)};Cluster.prototype.startAutoCleanup=function(){var base;this.stopAutoCleanup();return typeof(base=this.interval=setInterval(function(_this){return function(){var k,ref,results,time,v;time=Date.now();ref=_this.limiters;results=[];for(k in ref){v=ref[k];if(v._nextRequest+1e3*60*5<time){results.push(_this.deleteKey(k))}else{results.push(void 0)}}return results}}(this),1e3*30)).unref==="function"?base.unref():void 0};Cluster.prototype.stopAutoCleanup=function(){return clearInterval(this.interval)};return Cluster}();module.exports=Cluster}).call(this)},{"./Bottleneck":1}],3:[function(require,module,exports){(function(global){(function(){module.exports=require("./Bottleneck");if(global.window!=null){global.window.Bottleneck=module.exports}}).call(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./Bottleneck":1}]},{},[3]);
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){(function(){var Bottleneck,bind=function(fn,me){return function(){return fn.apply(me,arguments)}},slice=[].slice;Bottleneck=function(){var e;Bottleneck.strategy=Bottleneck.prototype.strategy={LEAK:1,OVERFLOW:2,BLOCK:3};Bottleneck.Cluster=Bottleneck.prototype.Cluster=require("./Cluster");Bottleneck.Promise=Bottleneck.prototype.Promise=function(){try{return require("bluebird")}catch(_error){e=_error;return typeof Promise!=="undefined"&&Promise!==null?Promise:function(){throw new Error("Bottleneck: install 'bluebird' or use Node 0.12 or higher for Promise support")}}}();function Bottleneck(maxNb,minTime,highWater,strategy){this.maxNb=maxNb!=null?maxNb:0;this.minTime=minTime!=null?minTime:0;this.highWater=highWater!=null?highWater:0;this.strategy=strategy!=null?strategy:Bottleneck.prototype.strategy.LEAK;this.submit=bind(this.submit,this);this._nextRequest=Date.now();this._nbRunning=0;this._queue=[];this._timeouts=[];this._unblockTime=0;this.penalty=15*this.minTime||5e3;this.interrupt=false;this.reservoir=null;this.limiter=null}Bottleneck.prototype.chain=function(limiter){this.limiter=limiter;return this};Bottleneck.prototype.isBlocked=function(){return this._unblockTime>=Date.now()};Bottleneck.prototype.check=function(){return(this._nbRunning<this.maxNb||this.maxNb<=0)&&this._nextRequest-Date.now()<=0&&(this.reservoir==null||this.reservoir>0)};Bottleneck.prototype._tryToRun=function(){var done,index,next,wait;if((this._nbRunning<this.maxNb||this.maxNb<=0)&&this._queue.length>0&&(this.reservoir==null||this.reservoir>0)){this._nbRunning++;if(this.reservoir!=null){this.reservoir--}wait=Math.max(this._nextRequest-Date.now(),0);this._nextRequest=Date.now()+wait+this.minTime;next=this._queue.shift();done=false;index=-1+this._timeouts.push(setTimeout(function(_this){return function(){var completed;completed=function(){var ref;if(!done){done=true;delete _this._timeouts[index];_this._nbRunning--;_this._tryToRun();if(!_this.interrupt){return(ref=next.cb)!=null?ref.apply({},Array.prototype.slice.call(arguments,0)):void 0}}};if(_this.limiter!=null){return _this.limiter.submit.apply(_this.limiter,Array.prototype.concat.call(next.task,next.args,completed))}else{return next.task.apply({},next.args.concat(completed))}}}(this),wait));return true}else{return false}};Bottleneck.prototype.submit=function(){var args,cb,i,reachedHighWaterMark,task;task=arguments[0],args=3<=arguments.length?slice.call(arguments,1,i=arguments.length-1):(i=1,[]),cb=arguments[i++];reachedHighWaterMark=this.highWater>0&&this._queue.length===this.highWater;if(this.strategy===Bottleneck.prototype.strategy.BLOCK&&(reachedHighWaterMark||this.isBlocked())){this._unblockTime=Date.now()+this.penalty;this._nextRequest=this._unblockTime+this.minTime;this._queue=[];return true}else if(reachedHighWaterMark){if(this.strategy===Bottleneck.prototype.strategy.LEAK){this._queue.shift()}else if(this.strategy===Bottleneck.prototype.strategy.OVERFLOW){return reachedHighWaterMark}}this._queue.push({task:task,args:args,cb:cb});this._tryToRun();return reachedHighWaterMark};Bottleneck.prototype.schedule=function(){var args,task,wrapped;task=arguments[0],args=2<=arguments.length?slice.call(arguments,1):[];wrapped=function(cb){return task.apply({},args).then(function(){var args;args=1<=arguments.length?slice.call(arguments,0):[];return cb.apply({},Array.prototype.concat.call([],null,args))})["catch"](function(){var args;args=1<=arguments.length?slice.call(arguments,0):[];return cb.apply({},Array.prototype.concat.call({},args))})};return new Bottleneck.prototype.Promise(function(_this){return function(resolve,reject){return _this.submit.apply({},Array.prototype.concat.call(wrapped,function(){var args,error;error=arguments[0],args=2<=arguments.length?slice.call(arguments,1):[];return(error!=null?reject:resolve).apply({},args)}))}}(this))};Bottleneck.prototype.changeSettings=function(maxNb,minTime,highWater,strategy){this.maxNb=maxNb!=null?maxNb:this.maxNb;this.minTime=minTime!=null?minTime:this.minTime;this.highWater=highWater!=null?highWater:this.highWater;this.strategy=strategy!=null?strategy:this.strategy;while(this._tryToRun()){}return this};Bottleneck.prototype.changePenalty=function(penalty){this.penalty=penalty!=null?penalty:this.penalty;return this};Bottleneck.prototype.changeReservoir=function(reservoir){this.reservoir=reservoir;while(this._tryToRun()){}return this};Bottleneck.prototype.incrementReservoir=function(incr){if(incr==null){incr=0}this.changeReservoir(this.reservoir+incr);return this};Bottleneck.prototype.stopAll=function(interrupt){var a,i,len,ref;this.interrupt=interrupt!=null?interrupt:this.interrupt;ref=this._timeouts;for(i=0,len=ref.length;i<len;i++){a=ref[i];clearTimeout(a)}this._tryToRun=function(){};this.submit=function(){return false};return this.check=function(){return false}};return Bottleneck}();module.exports=Bottleneck}).call(this)},{"./Cluster":2,bluebird:undefined}],2:[function(require,module,exports){(function(){var Cluster,hasProp={}.hasOwnProperty;Cluster=function(){function Cluster(maxNb,minTime,highWater,strategy){this.maxNb=maxNb;this.minTime=minTime;this.highWater=highWater;this.strategy=strategy;this.limiters={};this.Bottleneck=require("./Bottleneck");this.startAutoCleanup()}Cluster.prototype.key=function(key){var ref;if(key==null){key=""}return(ref=this.limiters[key])!=null?ref:this.limiters[key]=new this.Bottleneck(this.maxNb,this.minTime,this.highWater,this.strategy)};Cluster.prototype.deleteKey=function(key){if(key==null){key=""}return delete this.limiters[key]};Cluster.prototype.all=function(cb){var k,ref,results,v;ref=this.limiters;results=[];for(k in ref){if(!hasProp.call(ref,k))continue;v=ref[k];results.push(cb(v))}return results};Cluster.prototype.keys=function(){return Object.keys(this.limiters)};Cluster.prototype.startAutoCleanup=function(){var base;this.stopAutoCleanup();return typeof(base=this.interval=setInterval(function(_this){return function(){var k,ref,results,time,v;time=Date.now();ref=_this.limiters;results=[];for(k in ref){v=ref[k];if(v._nextRequest+1e3*60*5<time){results.push(_this.deleteKey(k))}else{results.push(void 0)}}return results}}(this),1e3*30)).unref==="function"?base.unref():void 0};Cluster.prototype.stopAutoCleanup=function(){return clearInterval(this.interval)};return Cluster}();module.exports=Cluster}).call(this)},{"./Bottleneck":1}],3:[function(require,module,exports){(function(global){(function(){module.exports=require("./Bottleneck");if(global.window!=null){global.window.Bottleneck=module.exports}}).call(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./Bottleneck":1}]},{},[3]);
{
"name": "bottleneck",
"main": "bottleneck.js",
"version": "1.9.0",
"version": "1.9.1",
"homepage": "https://github.com/SGrondin/bottleneck",

@@ -6,0 +6,0 @@ "authors": [

@@ -23,3 +23,5 @@ // Generated by CoffeeScript 1.9.3

e = _error;
return Promise;
return typeof Promise !== "undefined" && Promise !== null ? Promise : function() {
throw new Error("Bottleneck: install 'bluebird' or use Node 0.12 or higher for Promise support");
};
}

@@ -26,0 +28,0 @@ })();

{
"name": "bottleneck",
"version": "1.9.0",
"version": "1.9.1",
"description": "Async rate limiter",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -248,3 +248,3 @@ # bottleneck

Calling `stopAutoCleanup()` on a limiter will turn off its garbage collection, so limiters for keys that have not been used in over **5 minutes** will NOT be deleted anymore. It can be reenabled by calling `startAutoCleanup()`.
Calling `stopAutoCleanup()` on a cluster will turn off its garbage collection, so limiters for keys that have not been used in over **5 minutes** will NOT be deleted anymore. It can be reenabled by calling `startAutoCleanup()`.

@@ -251,0 +251,0 @@ ### startAutoCleanup()

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