Skip to content

Commit a83b5d7

Browse files
committed
Merge branch '2.0' into 3.2-features
2 parents 063f501 + aa8c18b commit a83b5d7

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

lib/cursor.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,31 @@ Cursor.prototype.hasNext = function(callback) {
182182
var self = this;
183183

184184
// Execute using callback
185-
if(typeof callback == 'function') return nextObject(self, function(err, doc) {
186-
if(!doc) return callback(null, false);
187-
self.s.currentDoc = doc;
188-
callback(null, true);
189-
});
185+
if(typeof callback == 'function') {
186+
if(self.s.currentDoc){
187+
return callback(null, true);
188+
} else {
189+
return nextObject(self, function(err, doc) {
190+
if(!doc) return callback(null, false);
191+
self.s.currentDoc = doc;
192+
callback(null, true);
193+
});
194+
}
195+
}
190196

191197
// Return a Promise
192198
return new this.s.promiseLibrary(function(resolve, reject) {
193-
nextObject(self, function(err, doc) {
194-
if(self.s.state == Cursor.CLOSED || self.isDead()) return resolve(false);
195-
if(err) return reject(err);
196-
if(!doc) return resolve(false);
197-
self.s.currentDoc = doc;
199+
if(self.s.currentDoc){
198200
resolve(true);
199-
});
201+
} else {
202+
nextObject(self, function(err, doc) {
203+
if(self.s.state == Cursor.CLOSED || self.isDead()) return resolve(false);
204+
if(err) return reject(err);
205+
if(!doc) return resolve(false);
206+
self.s.currentDoc = doc;
207+
resolve(true);
208+
});
209+
}
200210
});
201211
}
202212

0 commit comments

Comments
 (0)