Skip to content

Commit c431fe7

Browse files
fix: initialization of cursors with values
1 parent 8ef1fe6 commit c431fe7

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
@@ -681,7 +681,7 @@ export abstract class AbstractCursor<
681681
* a significant refactor.
682682
*/
683683
[kInit](callback: Callback<TSchema | null>): void {
684-
this._initialize(this[kSession], (err, state) => {
684+
this._initialize(this[kSession], (error, state) => {
685685
if (state) {
686686
const response = state.response;
687687
this[kServer] = state.server;
@@ -713,8 +713,12 @@ export abstract class AbstractCursor<
713713
// the cursor is now initialized, even if an error occurred or it is dead
714714
this[kInitialized] = true;
715715

716-
if (err || cursorIsDead(this)) {
717-
return cleanupCursor(this, { error: err }, () => callback(err, nextDocument(this)));
716+
if (error) {
717+
return cleanupCursor(this, { error }, () => callback(error, undefined));
718+
}
719+
720+
if (cursorIsDead(this)) {
721+
return cleanupCursor(this, undefined, () => callback());
718722
}
719723

720724
callback();
@@ -775,14 +779,8 @@ export function next<T>(
775779

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

0 commit comments

Comments
 (0)