* Try to get the next available document from the Change Stream's cursor or `null` if an empty batch is returned
()
| 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) { |