]> _ Git - cubist_util.git/commitdiff
wip #6202
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 21 Aug 2023 15:37:29 +0000 (17:37 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 21 Aug 2023 15:37:29 +0000 (17:37 +0200)
src/PHP.php

index bed218aefd305dda98764e6bf16b8c8d9e4f5dec..5ac41bf12ba185b16336383a1a17f2eea45e5b2b 100644 (file)
@@ -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;