Basically I have a code:
$response = myFunction();
I need to repeat this call if there was an error like this:
do {
$response = myFunction();
} while ( isset($response['error']) );
But I want to usleep(500); too if there was an error. I could do like this, but I don’t find it so elegant:
do {
$response = myFunction();
if (isset($response['error']))
usleep(500);
} while ( isset($response['error']) );
What Can i do? Maybe something like this (not very elegant neither)
while( isset($response['error']) && !usleep(500) );
Edit
There is another possibility… With the use of goto. But I am always reluctant to goto codes
retry:
$response = myFunction();
if (isset($response['error'])) {
usleep(500);
goto retry;
}
To me this seems the most clear and redundancy-free solution. What do you think?
Having said that, trying to hammer a function until it returns the correct result may be a sign of a badly thought-out architecture and there may be a better solution for the whole problem to begin with.