Skip to content

Commit eb2dee4

Browse files
committed
PHPLIB-322: Add resume logic to ChangeStream::rewind()
1 parent de2e331 commit eb2dee4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/ChangeStream.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,26 @@ public function next()
117117
*/
118118
public function rewind()
119119
{
120-
$this->csIt->rewind();
120+
$resumable = false;
121+
try {
122+
$this->csIt->rewind();
123+
if ($this->valid()) {
124+
$this->extractResumeToken($this->csIt->current());
125+
}
126+
} catch (RuntimeException $e) {
127+
if (strpos($e->getMessage(), "not master") !== false) {
128+
$resumable = true;
129+
}
130+
if ($e->getCode() === self::CURSOR_NOT_FOUND) {
131+
$resumable = true;
132+
}
133+
if ($e instanceof ConnectionTimeoutException) {
134+
$resumable = true;
135+
}
136+
}
137+
if ($resumable) {
138+
$this->resume();
139+
}
121140
}
122141

123142
/**

0 commit comments

Comments
 (0)