Skip to content

Commit e3bd359

Browse files
committed
add retry helper
1 parent 969e1fc commit e3bd359

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Illuminate/Support/helpers.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,33 @@ function preg_replace_array($pattern, array $replacements, $subject)
606606
}
607607
}
608608

609+
if (! function_exists('retry')) {
610+
/**
611+
* Retry an operation a given number of times.
612+
*
613+
* @param int $times
614+
* @param callable $callback
615+
* @return mixed
616+
*/
617+
function retry($times, callable $callback)
618+
{
619+
$times--;
620+
621+
beginning:
622+
try {
623+
return $callback();
624+
} catch (Exception $e) {
625+
if (! $times) {
626+
throw $e;
627+
}
628+
629+
$times--;
630+
631+
goto beginning;
632+
}
633+
}
634+
}
635+
609636
if (! function_exists('snake_case')) {
610637
/**
611638
* Convert a string to snake case.

0 commit comments

Comments
 (0)