diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 97f77d937ff8..410f9b3880ad 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -606,6 +606,33 @@ function preg_replace_array($pattern, array $replacements, $subject) } } +if (! function_exists('retry')) { + /** + * Retry an operation a given number of times. + * + * @param int $times + * @param callable $callback + * @return mixed + */ + function retry($times, callable $callback) + { + $times--; + + beginning: + try { + return $callback(); + } catch (Exception $e) { + if (! $times) { + throw $e; + } + + $times--; + + goto beginning; + } + } +} + if (! function_exists('snake_case')) { /** * Convert a string to snake case.