Skip to content

Instantly share code, notes, and snippets.

@ricardodantas
Last active August 4, 2017 19:59
Show Gist options
  • Select an option

  • Save ricardodantas/9da3ff4511c7ea32b09dc8205f140fdd to your computer and use it in GitHub Desktop.

Select an option

Save ricardodantas/9da3ff4511c7ea32b09dc8205f140fdd to your computer and use it in GitHub Desktop.
Ruby retry alternative for PHP
<?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