* @internal * * This function is exposed for the unified test runner's createChangeStream * operation. We cannot refactor to use the abstract _initialize method without * a significant refactor.
()
| 902 | * a significant refactor. |
| 903 | */ |
| 904 | private async cursorInit(): Promise<void> { |
| 905 | if (this.cursorOptions.timeoutMS != null) { |
| 906 | this.timeoutContext ??= new CursorTimeoutContext( |
| 907 | TimeoutContext.create({ |
| 908 | serverSelectionTimeoutMS: this.client.s.options.serverSelectionTimeoutMS, |
| 909 | timeoutMS: this.cursorOptions.timeoutMS |
| 910 | }), |
| 911 | this |
| 912 | ); |
| 913 | } |
| 914 | try { |
| 915 | this.cursorSession ??= this.cursorClient.startSession({ owner: this, explicit: false }); |
| 916 | const state = await this._initialize(this.cursorSession); |
| 917 | // Set omitMaxTimeMS to the value needed for subsequent getMore calls |
| 918 | this.cursorOptions.omitMaxTimeMS = this.cursorOptions.timeoutMS != null; |
| 919 | const response = state.response; |
| 920 | this.selectedServer = state.server; |
| 921 | this.cursorId = response.id; |
| 922 | this.cursorNamespace = response.ns ?? this.namespace; |
| 923 | this.documents = response; |
| 924 | this.initialized = true; // the cursor is now initialized, even if it is dead |
| 925 | } catch (error) { |
| 926 | // the cursor is now initialized, even if an error occurred |
| 927 | this.initialized = true; |
| 928 | await this.cleanup(undefined, error); |
| 929 | throw error; |
| 930 | } |
| 931 | |
| 932 | if (this.isDead) { |
| 933 | await this.cleanup(); |
| 934 | } |
| 935 | |
| 936 | return; |
| 937 | } |
| 938 | |
| 939 | /** @internal Attempt to obtain more documents */ |
| 940 | private async fetchBatch(): Promise<void> { |
nothing calls this directly
no test coverage detected