Browse Source

Refs #5121: Add EOF for the end of getNext

Chris Sexton 12 years ago
parent
commit
e2669d4885

+ 4 - 2
lib/pipeline/documentSources/CursorDocumentSource.js

@@ -1,5 +1,7 @@
 "use strict";
 "use strict";
 
 
+var DocumentSource = require('./DocumentSource');
+
 // Mimicking max memory size from mongo/db/query/new_find.cpp
 // Mimicking max memory size from mongo/db/query/new_find.cpp
 // Need to actually decide some size for this?
 // Need to actually decide some size for this?
 var MAX_BATCH_DOCS = 150;
 var MAX_BATCH_DOCS = 150;
@@ -81,8 +83,8 @@ proto.getNext = function getNext(callback) {
 
 
 		if (!this._currentBatch) {
 		if (!this._currentBatch) {
 			if (callback)
 			if (callback)
-				return callback(null);
-			return null;
+				return callback(DocumentSource.EOF);
+			return DocumentSource.EOF;
 		}
 		}
 	}
 	}
 
 

+ 16 - 1
lib/pipeline/documentSources/DocumentSource.js

@@ -37,6 +37,19 @@ var DocumentSource = module.exports = function DocumentSource(expCtx){
 
 
 }, klass = DocumentSource, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 }, klass = DocumentSource, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 
+klass.EOF = (function() {
+	/**
+	 * Holds a Cursor and all associated state required to access the cursor.
+	 * @class CursorWithContext
+	 * @namespace mungedb-aggregate.pipeline.documentSources.CursorDocumentSource
+	 * @module mungedb-aggregate
+	 * @constructor
+	 **/
+	var klass = function EOF(){
+	};
+	return klass;
+})();
+
 /*
 /*
 class DocumentSource :
 class DocumentSource :
 public IntrusiveCounterUnsigned,
 public IntrusiveCounterUnsigned,
@@ -67,8 +80,10 @@ proto.getPipelineStep = function getPipelineStep() {
 };
 };
 
 
 /**
 /**
+ * Returns the next Document if there is one or DocumentSource.EOF if at EOF.
+ *
  * some implementations do the equivalent of verify(!eof()) so check eof() first
  * some implementations do the equivalent of verify(!eof()) so check eof() first
- * @method	getNExt
+ * @method	getNext
  * @returns	{Document}	the current Document without advancing
  * @returns	{Document}	the current Document without advancing
  **/
  **/
 proto.getNext = function getNext(callback) {
 proto.getNext = function getNext(callback) {