Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added workersList() method into queue #891

Merged
merged 1 commit into from
Oct 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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