Permalink
Browse files

fix bug in order of queue events and improve tests - thanks Kami

  • Loading branch information...
1 parent 570cf8e commit 02531670be1d53fd4013cba8233e8c83418579a0 @caolan caolan committed Apr 27, 2011
Showing with 39 additions and 17 deletions.
  1. +1 −1 dist/async.min.js
  2. +1 −1 lib/async.js
  3. +1 −1 package.json
  4. +36 −14 test/test-async.js
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -561,13 +561,13 @@
if (workers < q.concurrency && tasks.length) {
var task = tasks.splice(0, 1)[0];
if(q.empty && tasks.length == 0) q.empty();
- if(q.drain && tasks.length + workers == 0) q.drain();
workers += 1;
worker(task.data, function () {
workers -= 1;
if (task.callback) {
task.callback.apply(task, arguments);
}
+ if(q.drain && tasks.length + workers == 0) q.drain();
q.process();
});
}
View
@@ -2,7 +2,7 @@
, "description": "Higher-order functions and common patterns for asynchronous code"
, "main": "./index"
, "author": "Caolan McMahon"
-, "version": "0.1.8"
+, "version": "0.1.9"
, "repository" :
{ "type" : "git"
, "url" : "http://github.com/caolan/async.git"
View
@@ -1321,25 +1321,47 @@ exports['falsy return values in parallel'] = function (test) {
};
exports['queue events'] = function(test) {
- test.expect(3);
+ var calls = [];
var q = async.queue(function(task, cb) {
// nop
+ calls.push('process ' + task);
cb();
}, 3);
-
+
q.saturated = function() {
- test.ok(q.length() == 3, 'queue should be saturated now');
- }
+ test.ok(q.length() == 3, 'queue should be saturated now');
+ calls.push('saturated');
+ };
q.empty = function() {
- test.ok(q.length() == 0, 'queue should be empty now');
- }
+ test.ok(q.length() == 0, 'queue should be empty now');
+ calls.push('empty');
+ };
q.drain = function() {
- test.ok(q.length() == 0 && q.running() == 0, 'queue should be empty now and no more workers should be running');
- test.done();
- }
- q.push('foo');
- q.push('bar');
- q.push('zoo');
- q.push('poo');
- q.push('moo');
+ test.ok(
+ q.length() == 0 && q.running() == 0,
+ 'queue should be empty now and no more workers should be running'
+ );
+ calls.push('drain');
+ test.same(calls, [
+ 'saturated',
+ 'process foo',
+ 'foo cb',
+ 'process bar',
+ 'bar cb',
+ 'process zoo',
+ 'zoo cb',
+ 'process poo',
+ 'poo cb',
+ 'empty',
+ 'process moo',
+ 'moo cb',
+ 'drain',
+ ]);
+ test.done();
+ };
+ q.push('foo', function () {calls.push('foo cb');});
+ q.push('bar', function () {calls.push('bar cb');});
+ q.push('zoo', function () {calls.push('zoo cb');});
+ q.push('poo', function () {calls.push('poo cb');});
+ q.push('moo', function () {calls.push('moo cb');});
};

0 comments on commit 0253167

Please sign in to comment.