bottleneck
Advanced tools
Comparing version 1.5.1 to 1.5.2
@@ -73,2 +73,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){ | ||
this._nextRequest = this._unblockTime + this.minTime; | ||
this._queue = []; | ||
return true; | ||
@@ -75,0 +76,0 @@ } else if (reachedHighWaterMark) { |
@@ -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,__slice=[].slice;Bottleneck=function(){Bottleneck.strategy=Bottleneck.prototype.strategy={LEAK:1,OVERFLOW:2,BLOCK:3};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._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}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(){return next.task.apply({},next.args.concat(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}}}))}}(this),wait));return true}else{return false}};Bottleneck.prototype.submit=function(){var args,cb,reachedHighWaterMark,task,_i;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._unblockTime>=Date.now())){this._unblockTime=Date.now()+this.penalty;this._nextRequest=this._unblockTime+this.minTime;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.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)},{}],2:[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}]},{},[2]); | ||
(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,__slice=[].slice;Bottleneck=function(){Bottleneck.strategy=Bottleneck.prototype.strategy={LEAK:1,OVERFLOW:2,BLOCK:3};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._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}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(){return next.task.apply({},next.args.concat(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}}}))}}(this),wait));return true}else{return false}};Bottleneck.prototype.submit=function(){var args,cb,reachedHighWaterMark,task,_i;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._unblockTime>=Date.now())){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.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)},{}],2:[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}]},{},[2]); |
{ | ||
"name": "bottleneck", | ||
"main": "bottleneck.js", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"homepage": "https://github.com/SGrondin/bottleneck", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -72,2 +72,3 @@ // Generated by CoffeeScript 1.7.1 | ||
this._nextRequest = this._unblockTime + this.minTime; | ||
this._queue = []; | ||
return true; | ||
@@ -74,0 +75,0 @@ } else if (reachedHighWaterMark) { |
{ | ||
"name": "bottleneck", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"description": "Async rate limiter", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -121,5 +121,5 @@ bottleneck | ||
For example, imagine that 3 minute-long requests are `submit`'ted at time T+0 with `maxConcurrent = 0` and `minTime = 2000`. The requests will be launched at T+0 seconds, T+2 seconds and T+4 seconds respectively. If right after adding the requests to Bottleneck, you were to call `limiter.changeSettings(1);`, it won't change the fact that there will be 3 requests running at the same time for roughly 60 seconds as in this example they each take a minute to complete. Once again, `changeSettings` only affects requests that have not yet been `submit`'ted. | ||
For example, imagine that 3 minute-long requests are submitted at time T+0 with `maxConcurrent = 0` and `minTime = 2000`. The requests will be launched at T+0 seconds, T+2 seconds and T+4 seconds respectively. If right after adding the requests to Bottleneck, you were to call `limiter.changeSettings(1);`, it won't change the fact that there will be 3 requests running at the same time for roughly 60 seconds as in this example they each take a minute to complete. Once again, `changeSettings` only affects requests that have not yet been submitted. | ||
This is by design, as Bottleneck made a promise to execute those requests according to the settings valid at the time. Changing settings afterwards should not retroactively affect space & time nor break previous assumptions as that would make code very error-prone and Bottleneck a tool that cannot be relied upon. | ||
This is by design, as Bottleneck made a promise to execute those requests according to the settings valid at the time. Changing settings afterwards should not retroactively affect space & time nor break previous assumptions, as that would make code very error-prone and Bottleneck a tool that cannot be relied upon. | ||
@@ -196,4 +196,6 @@ | ||
----- | ||
# Contributing | ||
Pull requests and suggestions are welcome. | ||
This README file is always in need of better explanations and examples. If things can be clearer and simpler, please consider forking this repo and submitting a Pull Request. | ||
Suggestions and bug reports are also welcome. |
Sorry, the diff of this file is not supported yet
27942
303
200