Permalink
Browse files

Groups with zero tasks are now terminated.

  • Loading branch information...
1 parent 720ba1c commit 2f654d61425401cbdd0b92770c25b174f4bf9150 @xavi- xavi- committed Feb 6, 2011
Showing with 24 additions and 15 deletions.
  1. +13 −15 lib/step.js
  2. +11 −0 test/groupTest.js
View
@@ -92,32 +92,30 @@ function Step() {
var counter = 0;
var result = [];
var error = undefined;
+
+ function check() {
+ if (counter === 0) {
+ // When group is done, call the callback
+ localCallback(error, result);
+ }
+ }
+ process.nextTick(check); // Ensures that check is called at least once
+
// Generates a callback for the group
return function () {
var i = counter;
counter++;
- function check() {
- counter--;
- if (counter === 0) {
- // When they're all done, call the callback
- localCallback(error, result);
- }
- }
return function () {
+ counter--;
// Compress the error from any result to the first argument
if (arguments[0]) {
error = arguments[0];
}
// Send the other results as arguments
result[i] = arguments[1];
- if (lock) {
- process.nextTick(check);
- return
- }
- check();
- }
-
- }
+ if (!lock) { check(); }
+ };
+ };
};
// Start the engine an pass nothing to the first step.
View
@@ -31,3 +31,14 @@ Step(
assert.deepEqual(dirResults, files);
}
);
+
+// Test to make sure groups of zero size terminate
+expect('group of zero terminated');
+Step(
+ function makeGroup() {
+ this.group();
+ },
+ function terminate() {
+ fulfill('group of zero terminated');
+ }
+)

0 comments on commit 2f654d6

Please sign in to comment.