Browse Source

Refs #2378: reverted move of setSource on input

Reverts 37bc8befd5a6ab1cb86cf7631905314a40185591
Kyle P Davis 12 years ago
parent
commit
f40942628b
1 changed files with 19 additions and 18 deletions
  1. 19 18
      lib/pipeline/Pipeline.js

+ 19 - 18
lib/pipeline/Pipeline.js

@@ -182,22 +182,23 @@ klass.parseCommand = function parseCommand(cmdObj, ctx){
  * @param	callback		{Function}			The callback function
 **/
 proto.run = function run(inputSource, callback){
-	if(inputSource && !(inputSource instanceof DocumentSource)) throw new Error("arg `inputSource` must be an instance of DocumentSource");
-	if(!callback) throw new Error("arg `callback` required");
+	if (inputSource && !(inputSource instanceof DocumentSource)) throw new Error("arg `inputSource` must be an instance of DocumentSource");
+	if (!callback) throw new Error("arg `callback` required");
 	var self = this;
-	// chain together the sources we found
-	var source = inputSource;
-	async.eachSeries(self.sourceVector,
-		function eachSrc(temp, next){
-			temp.setSource(source, function(err){
-				if (err) return next(err);
-				source = temp;
-				return next();
-			});
-		},
-		function doneSrcs(err){ //source is left pointing at the last source in the chain
-			if (err) return callback(err);
-			inputSource.setSource(undefined, function(err){	//TODO: HACK: temp solution to the fact that we need to initialize our source since we're using setSource as a workaround for the lack of real async cursors
+	inputSource.setSource(undefined, function(err){	//TODO: HACK: temp solution to the fact that we need to initialize our source since we're using setSource as a workaround for the lack of real async cursors
+		if (err) return callback(err);
+		// chain together the sources we found
+		var source = inputSource;
+		async.eachSeries(
+			self.sourceVector,
+			function eachSrc(temp, next){
+				temp.setSource(source, function(err){
+					if (err) return next(err);
+					source = temp;
+					return next();
+				});
+			},
+			function doneSrcs(err){ //source is left pointing at the last source in the chain
 				if (err) return callback(err);
 				/*
 				Iterate through the resulting documents, and add them to the result.
@@ -222,7 +223,7 @@ proto.run = function run(inputSource, callback){
 //					,ok: true;	//not actually in here... where does this come from?
 				};
 				return callback(null, result);
-			});
-		}
-	);
+			}
+		);
+	});
 };