Skip to content

Commit 3caa44c

Browse files
committed
PHP team feedback
1 parent 12588df commit 3caa44c

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

source/includes/read/change-streams/change-stream-options.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ function toJSON(object $document): string
2121
$changeStream = $collection->watch([], $options);
2222
$changeStream->rewind();
2323

24-
do {
24+
while (true) {
2525
$changeStream->next();
2626

2727
if ($changeStream->valid()) {
28-
$event = $changeStream->current();
29-
echo toJSON($event), PHP_EOL;
28+
continue;
3029
}
31-
} while (! $changeStream->valid() || $changeStream->current()['operationType'] !== 'invalidate');
30+
31+
$event = $changeStream->current();
32+
echo toJSON($event), PHP_EOL;
33+
34+
if ($changeStream->current()['operationType'] === 'invalidate') {
35+
break;
36+
}
37+
}
3238
// end-change-stream-post-image

source/includes/read/change-streams/change-stream-pipeline.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ function toJSON(object $document): string
2929
$changeStream = $collection->watch($pipeline);
3030
$changeStream->rewind();
3131

32-
do {
32+
while (true) {
3333
$changeStream->next();
3434

3535
if ($changeStream->valid()) {
36-
$event = $changeStream->current();
37-
echo toJSON($event), PHP_EOL;
36+
continue;
3837
}
39-
} while (! $changeStream->valid() || $changeStream->current()['operationType'] !== 'invalidate');
38+
39+
$event = $changeStream->current();
40+
echo toJSON($event), PHP_EOL;
41+
42+
if ($changeStream->current()['operationType'] === 'invalidate') {
43+
break;
44+
}
45+
}
4046
// end-change-stream-pipeline

source/includes/read/change-streams/change-stream.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ function toJSON(object $document): string
2828
echo toJSON($event), PHP_EOL;
2929
}
3030
} while (! $changeStream->valid() || $changeStream->current()['operationType'] !== 'invalidate');
31+
32+
while (true) {
33+
$changeStream->next();
34+
35+
if ($changeStream->valid()) {
36+
continue;
37+
}
38+
39+
$event = $changeStream->current();
40+
echo toJSON($event), PHP_EOL;
41+
42+
if ($changeStream->current()['operationType'] === 'invalidate') {
43+
break;
44+
}
45+
}
3146
// end-open-change-stream
3247

3348
// Updates a document that has a "name" value of "Blarney Castle"

source/includes/usage-examples/read-code-examples.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,18 @@
5454
$changeStream = $collection->watch();
5555
$changeStream->rewind();
5656

57-
do {
57+
while (true) {
5858
$changeStream->next();
5959

6060
if ($changeStream->valid()) {
61-
$event = $changeStream->current();
62-
echo toJSON($event) . PHP_EOL;
61+
continue;
6362
}
64-
} while (! $changeStream->valid() || $changeStream->current()['operationType'] !== 'invalidate');
63+
64+
$event = $changeStream->current();
65+
echo toJSON($event), PHP_EOL;
66+
67+
if ($changeStream->current()['operationType'] === 'invalidate') {
68+
break;
69+
}
70+
}
6571
// end-change-stream

0 commit comments

Comments
 (0)