Created
June 17, 2021 09:18
-
-
Save BackEndTea/10b123f1cc3164a23ffe5a25b90f2640 to your computer and use it in GitHub Desktop.
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 | |
function connect_while(ApiClient $client): string | |
{ | |
$tries = 0; | |
while(true) { | |
$tries++; | |
try { | |
$result = $client->doThing(); | |
break; | |
}catch(ApiException $e) { | |
if($tries === 10) { | |
throw $e; | |
} | |
echo "error with api, trying again"; | |
sleep(5); | |
} | |
} | |
return process($result); | |
} | |
function connect_goto(ApiClient $client): string | |
{ | |
$tries = 0; | |
start: | |
$tries++; | |
try { | |
$result = $client->doThing(); | |
break; | |
} catch(ApiException $e) { | |
if($tries === 10) { | |
throw $e; | |
} | |
echo "error with api, trying again"; | |
sleep(5); | |
goto start; | |
} | |
return process($result); | |
} |
zerkms
commented
Jun 17, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment