Check if there is any document still available in the Change Stream
()
| 711 | |
| 712 | /** Check if there is any document still available in the Change Stream */ |
| 713 | async hasNext(): Promise<boolean> { |
| 714 | this._setIsIterator(); |
| 715 | // Change streams must resume indefinitely while each resume event succeeds. |
| 716 | // This loop continues until either a change event is received or until a resume attempt |
| 717 | // fails. |
| 718 | |
| 719 | this.timeoutContext?.refresh(); |
| 720 | try { |
| 721 | while (true) { |
| 722 | try { |
| 723 | const hasNext = await this.cursor.hasNext(); |
| 724 | return hasNext; |
| 725 | } catch (error) { |
| 726 | try { |
| 727 | await this._processErrorIteratorMode(error, this.cursor.id != null); |
| 728 | } catch (error) { |
| 729 | if (error instanceof MongoOperationTimeoutError && this.cursor.id == null) { |
| 730 | throw error; |
| 731 | } |
| 732 | try { |
| 733 | await this.close(); |
| 734 | } catch (error) { |
| 735 | squashError(error); |
| 736 | } |
| 737 | throw error; |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | } finally { |
| 742 | this.timeoutContext?.clear(); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | /** Get the next available document from the Change Stream. */ |
| 747 | async next(): Promise<TChange> { |