Skip to content

Commit c83b820

Browse files
baileympearsonnbbeeken
authored andcommitted
fix: initialization of cursors with values
1 parent 816b1b7 commit c83b820

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/cursor/abstract_cursor.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ export abstract class AbstractCursor<
692692
* a significant refactor.
693693
*/
694694
[kInit](callback: Callback<TSchema | null>): void {
695-
this._initialize(this[kSession], (err, state) => {
695+
this._initialize(this[kSession], (error, state) => {
696696
if (state) {
697697
const response = state.response;
698698
this[kServer] = state.server;
@@ -724,8 +724,12 @@ export abstract class AbstractCursor<
724724
// the cursor is now initialized, even if an error occurred or it is dead
725725
this[kInitialized] = true;
726726

727-
if (err || cursorIsDead(this)) {
728-
return cleanupCursor(this, { error: err }, () => callback(err, nextDocument(this)));
727+
if (error) {
728+
return cleanupCursor(this, { error }, () => callback(error, undefined));
729+
}
730+
731+
if (cursorIsDead(this)) {
732+
return cleanupCursor(this, undefined, () => callback());
729733
}
730734

731735
callback();
@@ -778,14 +782,8 @@ export function next<T>(
778782

779783
if (cursorId == null) {
780784
// All cursors must operate within a session, one must be made implicitly if not explicitly provided
781-
cursor[kInit]((err, value) => {
785+
cursor[kInit](err => {
782786
if (err) return callback(err);
783-
// Intentional strict null check, because users can map cursors to falsey values.
784-
// We allow mapping to all values except for null.
785-
// eslint-disable-next-line no-restricted-syntax
786-
if (value !== null) {
787-
return callback(undefined, value);
788-
}
789787
return next(cursor, blocking, callback);
790788
});
791789

0 commit comments

Comments
 (0)