|
@@ -72,48 +72,17 @@ proto.coalesce = function coalesce(nextSource) {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-proto.getNext = function getNext(callback) {
|
|
|
|
|
- if (!callback) throw new Error(this.getSourceName() + " #getNext() requires callback");
|
|
|
|
|
-
|
|
|
|
|
- if (this.expCtx instanceof Object && this.expCtx.checkForInterrupt && this.expCtx.checkForInterrupt() === false)
|
|
|
|
|
- return callback(new Error("Interrupted"));
|
|
|
|
|
-
|
|
|
|
|
- var self = this,
|
|
|
|
|
- out;
|
|
|
|
|
- async.series(
|
|
|
|
|
- [
|
|
|
|
|
- function(next) {
|
|
|
|
|
- if (!self.populated)
|
|
|
|
|
- {
|
|
|
|
|
- self.populate(function(err) {
|
|
|
|
|
- return next(err);
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- return next();
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- function(next) {
|
|
|
|
|
- if (self.docIterator >= self.documents.length) {
|
|
|
|
|
- out = null;
|
|
|
|
|
- return next(null, null);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- var output = self.documents[self.docIterator++];
|
|
|
|
|
- if (!output || output === null) {
|
|
|
|
|
- out = null;
|
|
|
|
|
- return next(null, null);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- out = output;
|
|
|
|
|
- return next(null, output);
|
|
|
|
|
- }
|
|
|
|
|
- ],
|
|
|
|
|
- function(err, results) {
|
|
|
|
|
- return callback(err, out);
|
|
|
|
|
- }
|
|
|
|
|
- );
|
|
|
|
|
|
|
+proto.getNext = function getNext() {
|
|
|
|
|
+ if (this.expCtx && this.expCtx.checkForInterrupt) this.expCtx.checkForInterrupt();
|
|
|
|
|
+
|
|
|
|
|
+ if (!this.populated)
|
|
|
|
|
+ this.populate();
|
|
|
|
|
+
|
|
|
|
|
+ var output = this.documents[this.docIterator++];
|
|
|
|
|
+ if (!output)
|
|
|
|
|
+ return null;
|
|
|
|
|
|
|
|
- return out;
|
|
|
|
|
|
|
+ return output;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -184,48 +153,21 @@ proto.makeSortOptions = function makeSortOptions(){
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
-proto.populate = function populate(callback) {
|
|
|
|
|
- if ( this._mergePresorted ){
|
|
|
|
|
- // Skipping stuff about mergeCursors and commandShards
|
|
|
|
|
|
|
+proto.populate = function populate() {
|
|
|
|
|
+ if (this._mergePresorted) {
|
|
|
|
|
+ //NOTE: DEVIATION: skipping stuff about mergeCursors and commandShards
|
|
|
throw new Error("Merge presorted not implemented.");
|
|
throw new Error("Merge presorted not implemented.");
|
|
|
} else {
|
|
} else {
|
|
|
- /* pull everything from the underlying source */
|
|
|
|
|
- var self = this,
|
|
|
|
|
- next;
|
|
|
|
|
-
|
|
|
|
|
- async.doWhilst(
|
|
|
|
|
- function (cb) {
|
|
|
|
|
- self.source.getNext(function(err, doc) {
|
|
|
|
|
- next = doc;
|
|
|
|
|
-
|
|
|
|
|
- // Don't add EOF; it doesn't sort well.
|
|
|
|
|
- if (doc !== null)
|
|
|
|
|
- self.documents.push(doc);
|
|
|
|
|
-
|
|
|
|
|
- return cb();
|
|
|
|
|
- });
|
|
|
|
|
- },
|
|
|
|
|
- function() {
|
|
|
|
|
- return next !== null;
|
|
|
|
|
- },
|
|
|
|
|
- function(err) {
|
|
|
|
|
- try {
|
|
|
|
|
- /* sort the list */
|
|
|
|
|
- self.documents.sort(SortDocumentSource.prototype.compare.bind(self));
|
|
|
|
|
- } catch (ex) {
|
|
|
|
|
- return callback(ex);
|
|
|
|
|
- }
|
|
|
|
|
- /* start the sort iterator */
|
|
|
|
|
- self.docIterator = 0;
|
|
|
|
|
-
|
|
|
|
|
- self.populated = true;
|
|
|
|
|
- //self._output.reset(true);
|
|
|
|
|
- return callback();
|
|
|
|
|
|
|
+ var doc;
|
|
|
|
|
+ while((doc = this.source.getNext())) {
|
|
|
|
|
+ // Don't add EOF; it doesn't sort well.
|
|
|
|
|
+ if (doc !== null)
|
|
|
|
|
+ this.documents.push(doc);
|
|
|
}
|
|
}
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // sort the list
|
|
|
|
|
+ this.documents.sort(SortDocumentSource.prototype.compare.bind(this));
|
|
|
}
|
|
}
|
|
|
|
|
+ this.docIterator = 0;
|
|
|
this.populated = true;
|
|
this.populated = true;
|
|
|
};
|
|
};
|
|
|
|
|
|