Last active
August 4, 2017 19:59
-
-
Save ricardodantas/9da3ff4511c7ea32b09dc8205f140fdd to your computer and use it in GitHub Desktop.
Ruby retry alternative for PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Traits\General; | |
| trait Github { | |
| function retry($f, $delay = 2, $retries = 10){ | |
| try { | |
| return $f(); | |
| } catch (Exception $e) { | |
| if ($retries > 0) { | |
| sleep($delay); | |
| return retry($f, 2 * $delay, $retries - 1); | |
| } else { | |
| throw $e; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment