Skip to content

Commit

Permalink
nbQueued, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrondin committed Jan 9, 2016
1 parent d64427b commit c13cc73
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 41 deletions.
25 changes: 8 additions & 17 deletions bottleneck.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,16 @@
return [];
};

Bottleneck.prototype.hasJobs = function(priority) {
Bottleneck.prototype.nbQueued = function(priority) {
if (priority != null) {
return this._queues[this._sanitizePriority(priority)].length > 0;
return this._queues[this._sanitizePriority(priority)].length;
} else {
return this._queues.some(function(x) {
return x.length > 0;
});
return this._queues.reduce((function(a, b) {
return a + b.length;
}), 0);
}
};

Bottleneck.prototype._getNbJobs = function() {
return this._queues.reduce((function(a, b) {
return a + b.length;
}), 0);
};

Bottleneck.prototype._getFirst = function(arr) {
return this._find(arr, function(x) {
return x.length > 0;
Expand All @@ -127,7 +121,7 @@

Bottleneck.prototype._tryToRun = function() {
var done, index, next, wait;
if (this._conditionsCheck() && this.hasJobs()) {
if (this._conditionsCheck() && this.nbQueued() > 0) {
this._nbRunning++;
if (this.reservoir != null) {
this.reservoir--;
Expand Down Expand Up @@ -174,7 +168,7 @@
var args, cb, j, priority, reachedHighWaterMark, shifted, task;
priority = arguments[0], task = arguments[1], args = 4 <= arguments.length ? slice.call(arguments, 2, j = arguments.length - 1) : (j = 2, []), cb = arguments[j++];
priority = this._sanitizePriority(priority);
reachedHighWaterMark = this.highWater > 0 && this._getNbJobs() === this.highWater;
reachedHighWaterMark = this.highWater > 0 && this.nbQueued() === this.highWater;
if (this.strategy === Bottleneck.prototype.strategy.BLOCK && (reachedHighWaterMark || this.isBlocked())) {
this._unblockTime = Date.now() + this.penalty;
this._nextRequest = this._unblockTime + this.minTime;
Expand Down Expand Up @@ -264,10 +258,7 @@
clearTimeout(a);
}
this._tryToRun = function() {};
this.submit = function() {
return false;
};
return this.check = function() {
return this.check = this.submit = this.submitPriority = this.schedule = this.schedulePriority = function() {
return false;
};
};
Expand Down
Loading

0 comments on commit c13cc73

Please sign in to comment.