Skip to content

Commit bd8c314

Browse files
refactor: get rid of duplicate function
1 parent 9188851 commit bd8c314

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/change_stream.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -778,15 +778,6 @@ export class ChangeStream<
778778
this._processResumeQueue();
779779
};
780780

781-
// otherwise, raise an error and close the change stream
782-
const unresumableError = (err: AnyError) => {
783-
if (!callback) {
784-
this.emit(ChangeStream.ERROR, err);
785-
}
786-
787-
this.close(() => this._processResumeQueue(err));
788-
};
789-
790781
if (cursor && isResumableError(error, maxWireVersion(cursor.server))) {
791782
this.cursor = undefined;
792783

@@ -799,7 +790,7 @@ export class ChangeStream<
799790
const topology = getTopology(this.parent);
800791
this._waitForTopologyConnected(topology, { readPreference: cursor.readPreference }, err => {
801792
// if the topology can't reconnect, close the stream
802-
if (err) return unresumableError(err);
793+
if (err) return this._closeWithError(err);
803794

804795
// create a new cursor, preserving the old cursor's options
805796
const newCursor = this._createChangeStreamCursor(cursor.resumeOptions);
@@ -810,7 +801,7 @@ export class ChangeStream<
810801
// attempt to continue in iterator mode
811802
newCursor.hasNext(err => {
812803
// if there's an error immediately after resuming, close the stream
813-
if (err) return unresumableError(err);
804+
if (err) return this._closeWithError(err);
814805
resumeWithCursor(newCursor);
815806
});
816807
});

0 commit comments

Comments
 (0)