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

index 3a86f4216b95786d736455781571b660569209b9..bed218aefd305dda98764e6bf16b8c8d9e4f5dec 100644 (file)
@@ -77,4 +77,16 @@ class PHP
         if ($return) return $export; else echo $export;
     }
 
+
+    public static function retryOnError(callable $callback, $attempts = 3)
+    {
+        try {
+            return call_user_func($callback);
+        } catch (\Exception $e) {
+            if ($attemps > 0) {
+                return self::retryOnError($callback, $attempts - 1);
+            }
+            throw $e;
+        }
+    }
 }