Browse Source

fix unsafe usage of setImmediate

Kyle P Davis 10 years ago
parent
commit
6e0e5ff5d5
1 changed files with 6 additions and 6 deletions
  1. 6 6
      lib/pipeline/documentSources/CursorDocumentSource.js

+ 6 - 6
lib/pipeline/documentSources/CursorDocumentSource.js

@@ -86,7 +86,7 @@ proto._loadBatch = function _loadBatch(callback) {
 		whileShouldBreak = false, // mimic while loop break in async land
 		whileShouldReturn = false; // mimic while loop return in async land
 	return async.whilst(
-		function test(){
+		function test() {
 			return !whileShouldBreak && !whileShouldReturn;
 		},
 		function(next) {
@@ -119,9 +119,9 @@ proto._loadBatch = function _loadBatch(callback) {
 				return next();
 			});
 		},
-		function(err){
-			if (whileShouldReturn){
-				return setImmediate(function() {
+		function(err) {
+			if (whileShouldReturn) {
+				return async.nextTick(function() {
 					callback(err);
 				});
 			}
@@ -131,11 +131,11 @@ proto._loadBatch = function _loadBatch(callback) {
 			self._runner = undefined;
 
 			//NOTE: DEVIATION FROM MONGO: to ensure that the callstack does not get too large if the Runner does things syncronously
-			if (self._firstRun || !self._currentBatch.length){
+			if (self._firstRun || !self._currentBatch.length) {
 				self._firstRun = false;
 				callback(err);
 			} else {
-				return setImmediate(function(){
+				return async.nextTick(function() {
 					callback(err);
 				});
 			}