Get the next available document from the Change Stream.
()
| 745 | |
| 746 | /** Get the next available document from the Change Stream. */ |
| 747 | async next(): Promise<TChange> { |
| 748 | this._setIsIterator(); |
| 749 | // Change streams must resume indefinitely while each resume event succeeds. |
| 750 | // This loop continues until either a change event is received or until a resume attempt |
| 751 | // fails. |
| 752 | this.timeoutContext?.refresh(); |
| 753 | |
| 754 | try { |
| 755 | while (true) { |
| 756 | try { |
| 757 | const change = await this.cursor.next(); |
| 758 | const processedChange = this._processChange(change ?? null); |
| 759 | return processedChange; |
| 760 | } catch (error) { |
| 761 | try { |
| 762 | await this._processErrorIteratorMode(error, this.cursor.id != null); |
| 763 | } catch (error) { |
| 764 | if (error instanceof MongoOperationTimeoutError && this.cursor.id == null) { |
| 765 | throw error; |
| 766 | } |
| 767 | try { |
| 768 | await this.close(); |
| 769 | } catch (error) { |
| 770 | squashError(error); |
| 771 | } |
| 772 | throw error; |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | } finally { |
| 777 | this.timeoutContext?.clear(); |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * Try to get the next available document from the Change Stream's cursor or `null` if an empty batch is returned |
no test coverage detected