Skip to content

Commit

Permalink
Added workersList() method into queue
Browse files Browse the repository at this point in the history
  • Loading branch information
kolomiichenko committed Aug 24, 2015
1 parent 92f78ae commit 4ebb214
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 4ebb214

Please sign in to comment.