Skip to content

Commit 8315cbe

Browse files
use while(true) instead of for(;;) w/ lint disable comments
1 parent fab50dc commit 8315cbe

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Diff for: src/change_stream.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,11 @@ export class ChangeStream<
648648
hasNext(callback?: Callback): Promise<boolean> | void {
649649
this._setIsIterator();
650650
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) {
652656
try {
653657
const hasNext = await this.cursor.hasNext();
654658
return hasNext;
@@ -675,7 +679,11 @@ export class ChangeStream<
675679
next(callback?: Callback<TChange>): Promise<TChange> | void {
676680
this._setIsIterator();
677681
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) {
679687
try {
680688
const change = await this.cursor.next();
681689
const processedChange = this._processChange(change ?? null);
@@ -705,7 +713,11 @@ export class ChangeStream<
705713
tryNext(callback?: Callback<Document | null>): Promise<Document | null> | void {
706714
this._setIsIterator();
707715
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) {
709721
try {
710722
const change = await this.cursor.tryNext();
711723
return change ?? null;

0 commit comments

Comments
 (0)