Skip to content

Commit

Permalink
Merge pull request #891 from kolomiichenko/master
Browse files Browse the repository at this point in the history
Added workersList() method into queue
  • Loading branch information
aearly committed Oct 26, 2015
2 parents 4a536f1 + 4ebb214 commit 7db25c7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ methods:
* `length()` - a function returning the number of items waiting to be processed.
* `started` - a function returning whether or not any items have been pushed and processed by the queue
* `running()` - a function returning the number of items currently being processed.
* `workersList()` - a function returning the array of items currently being processed.
* `idle()` - a function returning false if there are items waiting or being processed, or true if not.
* `concurrency` - an integer for determining how many `worker` functions should be
run in parallel. This property can be changed after a `queue` is created to
Expand Down
14 changes: 14 additions & 0 deletions dist/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,17 @@
function _next(q, tasks) {
return function(){
workers -= 1;

var removed = false;
var args = arguments;
_arrayEach(tasks, function (task) {
_arrayEach(workersList, function (worker, index) {
if (worker === task && !removed) {
workersList.splice(index, 1);
removed = true;
}
});

task.callback.apply(task, args);
});
if (q.tasks.length + workers === 0) {
Expand All @@ -875,6 +884,7 @@
}

var workers = 0;
var workersList = [];
var q = {
tasks: [],
concurrency: concurrency,
Expand Down Expand Up @@ -909,6 +919,7 @@
q.empty();
}
workers += 1;
workersList.push(tasks[0]);
var cb = only_once(_next(q, tasks));
worker(data, cb);
}
Expand All @@ -920,6 +931,9 @@
running: function () {
return workers;
},
workersList: function () {
return workersList;
},
idle: function() {
return q.tasks.length + workers === 0;
},
Expand Down
2 changes: 1 addition & 1 deletion dist/async.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 7db25c7

Please sign in to comment.