MCPcopy
hub / github.com/mongodb/node-mongodb-native / tryNext

Method tryNext

src/change_stream.ts:784–817  ·  view source on GitHub ↗

* Try to get the next available document from the Change Stream's cursor or `null` if an empty batch is returned

()

Source from the content-addressed store, hash-verified

782 * Try to get the next available document from the Change Stream's cursor or `null` if an empty batch is returned
783 */
784 async tryNext(): Promise<TChange | null> {
785 this._setIsIterator();
786 // Change streams must resume indefinitely while each resume event succeeds.
787 // This loop continues until either a change event is received or until a resume attempt
788 // fails.
789 this.timeoutContext?.refresh();
790
791 try {
792 while (true) {
793 try {
794 const change = await this.cursor.tryNext();
795 if (!change) {
796 return null;
797 }
798 const processedChange = this._processChange(change);
799 return processedChange;
800 } catch (error) {
801 try {
802 await this._processErrorIteratorMode(error, this.cursor.id != null);
803 } catch (error) {
804 if (error instanceof MongoOperationTimeoutError && this.cursor.id == null) throw error;
805 try {
806 await this.close();
807 } catch (error) {
808 squashError(error);
809 }
810 throw error;
811 }
812 }
813 }
814 } finally {
815 this.timeoutContext?.clear();
816 }
817 }
818
819 async *[Symbol.asyncIterator](): AsyncGenerator<TChange, void, void> {
820 if (this.closed) {

Callers 10

operations.tsFile · 0.80
testFunction · 0.80
operationFunction · 0.80

Calls 7

_setIsIteratorMethod · 0.95
_processChangeMethod · 0.95
closeMethod · 0.95
squashErrorFunction · 0.90
refreshMethod · 0.45
clearMethod · 0.45

Tested by 2

testFunction · 0.64
operationFunction · 0.64