protected function retry(\Closure $retry)
{
$numRetries = $this->config->getRetryConnect();
if ($numRetries < 1) {
return $retry();
}
$firstException = null;
for ($i = 0; $i <= $numRetries; $i++) {
try {
return $retry();
} catch (\MongoException $e) {
if ($firstException === null) {
$firstException = $e;
}
if ($i === $numRetries) {
throw $firstException;
}
}
}
}