From: Vincent Vanwaelscappel Date: Mon, 21 Aug 2023 15:37:29 +0000 (+0200) Subject: wip #6202 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=a6dff412786ee7100ca09aa4f9fd49160a07e223;p=cubist_util.git wip #6202 --- diff --git a/src/PHP.php b/src/PHP.php index bed218a..5ac41bf 100644 --- a/src/PHP.php +++ b/src/PHP.php @@ -78,12 +78,21 @@ class PHP } - public static function retryOnError(callable $callback, $attempts = 3) + /** + * @param callable $callback + * @param $attempts int + * @param $pauseBetweenAttemps float + * @return mixed + */ + public static function retryOnError(callable $callback, $attempts = 3, $pauseBetweenAttemps = 0) { try { return call_user_func($callback); } catch (\Exception $e) { if ($attemps > 0) { + if ($pauseBetweenAttemps > 0) { + usleep($pauseBetweenAttemps / 1000000); + } return self::retryOnError($callback, $attempts - 1); } throw $e;