Skip to content

Commit

Permalink
allow queue.push without a callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Caolan McMahon committed Nov 17, 2010
1 parent b4d3709 commit 960b9bf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/async.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/async.js
Expand Up @@ -559,7 +559,9 @@
workers += 1;
worker(task.data, function () {
workers -= 1;
task.callback.apply(task, arguments);
if (task.callback) {
task.callback.apply(task, arguments);
}
q.process();
});
}
Expand Down
31 changes: 31 additions & 0 deletions test/test-async.js
Expand Up @@ -1160,3 +1160,34 @@ exports['queue changing concurrency'] = function (test) {
test.done();
}, 100);
};

exports['queue push without callback'] = function (test) {
var call_order = [],
delays = [20,10,30,10];

// worker1: --1-4
// worker2: -2---3
// order of completion: 2,1,4,3

var q = async.queue(function (task, callback) {
setTimeout(function () {
call_order.push('process ' + task);
callback('error', 'arg');
}, delays.splice(0,1)[0]);
}, 2);

q.push(1);
q.push(2);
q.push(3);
q.push(4);

setTimeout(function () {
test.same(call_order, [
'process 2',
'process 1',
'process 4',
'process 3'
]);
test.done();
}, 60);
};

0 comments on commit 960b9bf

Please sign in to comment.