Permalink
Browse files

Fixed indentation.

  • Loading branch information...
1 parent 05f992e commit 794b432c1ebde0193070cb251f08627b1c2e1116 @alexkwolfe committed Sep 9, 2010
Showing with 82 additions and 82 deletions.
  1. +82 −82 lib/groupie.js
View
@@ -17,59 +17,59 @@ var sys = require('sys');
* g.finalize();
*/
exports.group = function () {
- var args = Array.prototype.slice.call(arguments);
- var cb = args.pop();
- var fxns = args.length > 0 && Array.isArray(args[0]) ? args.shift() : null;
- var open = fxns === null;
- var finalized = !open;
+ var args = Array.prototype.slice.call(arguments);
+ var cb = args.pop();
+ var fxns = args.length > 0 && Array.isArray(args[0]) ? args.shift() : null;
+ var open = fxns === null;
+ var finalized = !open;
fxns = fxns || [];
- var items_left_to_execute = fxns.length;
- var results = [];
- var errOccurred = false;
- var callGroupFunction = function(i, fxn) {
- var done = function(err, result) {
- if (errOccurred) return;
- if (err) {
- errOccurred = true;
- return cb(err, results);
- }
- results[i] = result;
- items_left_to_execute--;
- if (finalized && !items_left_to_execute) {
- cb(null, results);
- }
- };
-
- try {
- fxn(done);
- } catch (err) {
- sys.puts("ERR: " + err);
- done(err, results);
- }
- };
+ var items_left_to_execute = fxns.length;
+ var results = [];
+ var errOccurred = false;
+ var callGroupFunction = function(i, fxn) {
+ var done = function(err, result) {
+ if (errOccurred) return;
+ if (err) {
+ errOccurred = true;
+ return cb(err, results);
+ }
+ results[i] = result;
+ items_left_to_execute--;
+ if (finalized && !items_left_to_execute) {
+ cb(null, results);
+ }
+ };
+
+ try {
+ fxn(done);
+ } catch (err) {
+ sys.puts("ERR: " + err);
+ done(err, results);
+ }
+ };
if (fxns.length === 0 && !open)
cb(null, []);
- for ( var i = 0; i < fxns.length; i++) {
- callGroupFunction(i, fxns[i]);
- }
-
- if (open)
- return {
- add: function(fxn) {
- items_left_to_execute++;
- callGroupFunction(fxns.push(fxn) - 1, fxn);
- },
- finalize: function() {
- finalized = true;
- if (!errOccurred && !items_left_to_execute)
- cb(null, results);
- }
- }
+ for ( var i = 0; i < fxns.length; i++) {
+ callGroupFunction(i, fxns[i]);
+ }
+
+ if (open)
+ return {
+ add: function(fxn) {
+ items_left_to_execute++;
+ callGroupFunction(fxns.push(fxn) - 1, fxn);
+ },
+ finalize: function() {
+ finalized = true;
+ if (!errOccurred && !items_left_to_execute)
+ cb(null, results);
+ }
+ }
}
/**
* Executes all functions in order, and a callback when all have completed
@@ -79,54 +79,54 @@ exports.group = function () {
* and the results of the chain operation, in order.
*/
exports.chain = function () {
- var args = Array.prototype.slice.call(arguments);
- var cb = args.pop();
- var fxns = args.length > 0 && Array.isArray(args[0]) ? args.shift() : null;
- var open = fxns === null;
- var finalized = !open;
+ var args = Array.prototype.slice.call(arguments);
+ var cb = args.pop();
+ var fxns = args.length > 0 && Array.isArray(args[0]) ? args.shift() : null;
+ var open = fxns === null;
+ var finalized = !open;
fxns = fxns || [];
var pos = 0;
- var results = [];
-
- var hasMore = function() {
- return fxns.length > pos;
- };
-
+ var results = [];
+
+ var hasMore = function() {
+ return fxns.length > pos;
+ };
+
var callNext = function() {
- var done = function(err, result) {
- if (err) return cb(err, results);
-
- pos++;
- results.push(result);
-
+ var done = function(err, result) {
+ if (err) return cb(err, results);
+
+ pos++;
+ results.push(result);
+
if (hasMore())
callNext();
- else if (finalized)
- cb(null, results);
+ else if (finalized)
+ cb(null, results);
};
- try {
- fxns[pos](done);
- } catch (err) {
- cb(err, results);
- }
+ try {
+ fxns[pos](done);
+ } catch (err) {
+ cb(err, results);
+ }
};
- if (fxns.length > 0)
- callNext();
+ if (fxns.length > 0)
+ callNext();
else if (!open)
cb(null, []);
- if (open)
- return {
- add: function(fxn) {
- fxns.push(fxn);
- if (hasMore()) callNext();
- },
- finalize: function() {
- finalized = true;
- if (!hasMore()) cb(null, results);
- }
- }
+ if (open)
+ return {
+ add: function(fxn) {
+ fxns.push(fxn);
+ if (hasMore()) callNext();
+ },
+ finalize: function() {
+ finalized = true;
+ if (!hasMore()) cb(null, results);
+ }
+ }
}

0 comments on commit 794b432

Please sign in to comment.