Skip to content

Commit

Permalink
1.1.1 Fixed memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrondin committed Mar 23, 2014
1 parent b264450 commit f111e6d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions bottleneck.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@
}

Bottleneck.prototype._tryToRun = function() {
var done, next, wait;
var done, index, next, wait;
if ((this._nbRunning < this.maxNb || this.maxNb <= 0) && this._queue.length > 0) {
this._nbRunning++;
wait = Math.max(this._nextRequest - Date.now(), 0);
this._nextRequest = Date.now() + wait + this.minTime;
next = this._queue.shift();
done = false;
return this._timeouts.push(setTimeout((function(_this) {
return index = this._timeouts.push(setTimeout((function(_this) {
return function() {
return next.task.apply({}, next.args.concat(function() {
var _ref;
if (!done) {
done = true;
_this._timeouts[index - 1] = null;
_this._nbRunning--;
_this._tryToRun();
return (_ref = next.cb) != null ? _ref.apply({}, Array.prototype.slice.call(arguments, 0)) : void 0;
Expand Down
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.

5 changes: 3 additions & 2 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.1.0",
"version": "1.1.1",
"description": "Async rate limiter",
"main": "lib/index.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/Bottleneck.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ class Bottleneck
@_nextRequest = Date.now() + wait + @minTime
next = @_queue.shift()
done = false
@_timeouts.push setTimeout () =>
index = @_timeouts.push setTimeout () =>
next.task.apply {}, next.args.concat () =>
if not done
done = true
@_timeouts[index-1] = null
@_nbRunning--
@_tryToRun()
next.cb?.apply {}, Array::slice.call arguments, 0
Expand Down

0 comments on commit f111e6d

Please sign in to comment.