Skip to content

Commit

Permalink
1.5.1 Fix small changeSettings bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrondin committed Jul 26, 2014
1 parent d25bb71 commit 11a8bee
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ And now you can be assured that someAsyncCall will abide by your rate guidelines

Bottleneck builds a queue of requests and executes them as soon as possible. All the requests will be executed *in order*.

This is sufficient for the vast majority of applications. Read the [Gotchas](https://github.com/SGrondin/bottleneck#gotchas) section and you're good to go. Or keep reading to learn about the fine tuning available for the more complex cases.
This is sufficient for the vast majority of applications. Read the [Gotchas](https://github.com/SGrondin/bottleneck#gotchas) section and you're good to go. Or keep reading to learn about all the fine tuning available for the more complex cases.


#Docs
Expand Down Expand Up @@ -116,6 +116,12 @@ limiter.changeSettings(maxConcurrent, minTime, highWater, strategy);
```
Same parameters as the constructor, pass ```null``` to skip a parameter and keep it to its current value.

**Note:** Changing `maxConcurrent` and `minTime` will not affect requests that have already been scheduled for execution.

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.

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.


###changePenalty()
```javascript
Expand Down
7 changes: 4 additions & 3 deletions bottleneck.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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 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){
// Generated by CoffeeScript 1.7.1
(function() {
var Bottleneck,
Expand Down Expand Up @@ -92,6 +92,7 @@
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;
};

Expand Down Expand Up @@ -151,5 +152,5 @@

}).call(this);

}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./Bottleneck":1}]},{},[2])
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./Bottleneck":1}]},{},[2]);
2 changes: 1 addition & 1 deletion bottleneck.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bottleneck",
"main": "bottleneck.js",
"version": "1.5.0",
"version": "1.5.1",
"homepage": "https://github.com/SGrondin/bottleneck",
"authors": [
"SGrondin <github@simongrondin.name>"
Expand Down
1 change: 1 addition & 0 deletions lib/Bottleneck.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bottleneck",
"version": "1.5.0",
"version": "1.5.1",
"description": "Async rate limiter",
"main": "lib/index.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion src/Bottleneck.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class Bottleneck
@_queue.push {task, args, cb}
@_tryToRun()
reachedHighWaterMark
changeSettings: (@maxNb=@maxNb, @minTime=@minTime, @highWater=@highWater, @strategy=@strategy) -> @
changeSettings: (@maxNb=@maxNb, @minTime=@minTime, @highWater=@highWater, @strategy=@strategy) ->
while @_tryToRun() then
@
changePenalty: (@penalty=@penalty) -> @
changeReservoir: (@reservoir) ->
while @_tryToRun() then
Expand Down

0 comments on commit 11a8bee

Please sign in to comment.