[Pkg-javascript-commits] [node-async] 292/480: added default concurrency for queue, closes #249
Jonas Smedegaard
js at moszumanska.debian.org
Fri May 2 08:58:35 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository node-async.
commit b63b80abb77603e8b17bc3213c498d49fcb35e1f
Author: Caolan McMahon <caolan at caolanmcmahon.com>
Date: Sat Mar 2 20:44:29 2013 +0000
added default concurrency for queue, closes #249
---
lib/async.js | 3 +++
test/test-async.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/lib/async.js b/lib/async.js
index 3ebad60..5aac1b1 100755
--- a/lib/async.js
+++ b/lib/async.js
@@ -693,6 +693,9 @@
};
async.queue = function (worker, concurrency) {
+ if (concurrency === undefined) {
+ concurrency = 1;
+ }
function _insert(q, data, pos, callback) {
if(data.constructor !== Array) {
data = [data];
diff --git a/test/test-async.js b/test/test-async.js
index e9efdd3..ddc86fe 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -1689,6 +1689,59 @@ exports['queue'] = function (test) {
};
};
+exports['queue default concurrency'] = function (test) {
+ var call_order = [],
+ delays = [160,80,240,80];
+
+ // order of completion: 1,2,3,4
+
+ var q = async.queue(function (task, callback) {
+ setTimeout(function () {
+ call_order.push('process ' + task);
+ callback('error', 'arg');
+ }, delays.splice(0,1)[0]);
+ });
+
+ q.push(1, function (err, arg) {
+ test.equal(err, 'error');
+ test.equal(arg, 'arg');
+ test.equal(q.length(), 3);
+ call_order.push('callback ' + 1);
+ });
+ q.push(2, function (err, arg) {
+ test.equal(err, 'error');
+ test.equal(arg, 'arg');
+ test.equal(q.length(), 2);
+ call_order.push('callback ' + 2);
+ });
+ q.push(3, function (err, arg) {
+ test.equal(err, 'error');
+ test.equal(arg, 'arg');
+ test.equal(q.length(), 1);
+ call_order.push('callback ' + 3);
+ });
+ q.push(4, function (err, arg) {
+ test.equal(err, 'error');
+ test.equal(arg, 'arg');
+ test.equal(q.length(), 0);
+ call_order.push('callback ' + 4);
+ });
+ test.equal(q.length(), 4);
+ test.equal(q.concurrency, 1);
+
+ q.drain = function () {
+ test.same(call_order, [
+ 'process 1', 'callback 1',
+ 'process 2', 'callback 2',
+ 'process 3', 'callback 3',
+ 'process 4', 'callback 4'
+ ]);
+ test.equal(q.concurrency, 1);
+ test.equal(q.length(), 0);
+ test.done();
+ };
+};
+
exports['queue error propagation'] = function(test){
var results = [];
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-async.git
More information about the Pkg-javascript-commits
mailing list