Procházet zdrojové kódy

refs #2063 fixed DocumentSource setSource to really be async

Phil Murray před 13 roky
rodič
revize
004791142e

+ 4 - 4
lib/pipeline/Pipeline.js

@@ -155,11 +155,11 @@ var Pipeline = module.exports = (function(){
 		if(!callback)
 			throw new Error("run requires callback");
 
-		async.eachSeries(this.sourceVector, function(item, callback){
-				item.setSource(source, function(err, pSource){
-					if(err) return callback(err);
+		async.eachSeries(this.sourceVector, function(item, next){
+				item.setSource(source, function(err){
+					if(err) return next(err);
 					source = item;
-					return callback();
+					return next();
 				});
 			},
 			function(err){

+ 3 - 2
lib/pipeline/documentSources/DocumentSource.js

@@ -146,12 +146,13 @@ public:
      * @param	{DocumentSource}	pSource	the underlying source to use
     **/
     proto.setSource = function setSource(pTheSource, callback) {
+		
 		if(this.pSource){
 			throw new Error("It is an error to set the source more than once");
 		}
         this.pSource = pTheSource;
-        if(callback)
-            return callback(null, this.pSource);
+        if (callback)
+			return process.nextTick(function(){callback();});
     };
     
     

+ 6 - 4
test/lib/pipeline/Pipeline.js

@@ -100,20 +100,22 @@ module.exports = {
 		},
 
 		"#run": {
-			"should set the parent source for all sources in the pipeline except the first one":function(){
+			"should set the parent source for all sources in the pipeline except the first one":function(next){
 				var p = Pipeline.parseCommand([{$test:{coalesce:false}}, {$test:{coalesce:false}}, {$test:{coalesce:false}}]);
-				p.run({}, [], function(err, result){
+				p.run({}, function(err, result){
 					assert.equal(p.sourceVector[1].pSource, p.sourceVector[0]);
 					assert.equal(p.sourceVector[2].pSource, p.sourceVector[1]);
+					next();
 				});
 
 			},
-			"should iterate through sources and return resultant array":function(){
+			"should iterate through sources and return resultant array":function(next){
 				var p = Pipeline.parseCommand([{$test:{coalesce:false}}, {$test:{coalesce:false}}, {$test:{coalesce:false}}]),
 					result = {};
-				p.run(result, [], function(err, result){
+				p.run(result, function(err, result){
 
 					assert.deepEqual(result.result, [5,4,3,2,1,0]);//see the test source for why this should be so
+					next();
 				});
 
 			}