@@ -648,7 +648,11 @@ export class ChangeStream<
648
648
hasNext ( callback ?: Callback ) : Promise < boolean > | void {
649
649
this . _setIsIterator ( ) ;
650
650
return maybeCallback ( async ( ) => {
651
- for ( ; ; ) {
651
+ // Change streams must resume indefinitely as long while each resume event succeeds.
652
+ // This loop continues until either a change event is received or until a resume attempt
653
+ // fails.
654
+ // eslint-disable-next-line no-constant-condition
655
+ while ( true ) {
652
656
try {
653
657
const hasNext = await this . cursor . hasNext ( ) ;
654
658
return hasNext ;
@@ -675,7 +679,11 @@ export class ChangeStream<
675
679
next ( callback ?: Callback < TChange > ) : Promise < TChange > | void {
676
680
this . _setIsIterator ( ) ;
677
681
return maybeCallback ( async ( ) => {
678
- for ( ; ; ) {
682
+ // Change streams must resume indefinitely as long while each resume event succeeds.
683
+ // This loop continues until either a change event is received or until a resume attempt
684
+ // fails.
685
+ // eslint-disable-next-line no-constant-condition
686
+ while ( true ) {
679
687
try {
680
688
const change = await this . cursor . next ( ) ;
681
689
const processedChange = this . _processChange ( change ?? null ) ;
@@ -705,7 +713,11 @@ export class ChangeStream<
705
713
tryNext ( callback ?: Callback < Document | null > ) : Promise < Document | null > | void {
706
714
this . _setIsIterator ( ) ;
707
715
return maybeCallback ( async ( ) => {
708
- for ( ; ; ) {
716
+ // Change streams must resume indefinitely as long while each resume event succeeds.
717
+ // This loop continues until either a change event is received or until a resume attempt
718
+ // fails.
719
+ // eslint-disable-next-line no-constant-condition
720
+ while ( true ) {
709
721
try {
710
722
const change = await this . cursor . tryNext ( ) ;
711
723
return change ?? null ;
0 commit comments