has_next.js
1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const Aspect = require('./operation').Aspect;
const defineAspects = require('./operation').defineAspects;
const loadCursor = require('../dynamic_loaders').loadCursor;
const OperationBase = require('./operation').OperationBase;
const nextObject = require('./common_functions').nextObject;
class HasNextOperation extends OperationBase {
constructor(cursor) {
super();
this.cursor = cursor;
}
execute(callback) {
const cursor = this.cursor;
let Cursor = loadCursor();
if (cursor.s.currentDoc) {
return callback(null, true);
}
if (cursor.isNotified()) {
return callback(null, false);
}
nextObject(cursor, (err, doc) => {
if (err) return callback(err, null);
if (cursor.s.state === Cursor.CLOSED || cursor.isDead()) return callback(null, false);
if (!doc) return callback(null, false);
cursor.s.currentDoc = doc;
callback(null, true);
});
}
}
defineAspects(HasNextOperation, Aspect.SKIP_SESSION);
module.exports = HasNextOperation;