I have a completable future defined below
CompletableFuture<Person> personFutures = personService.getPersons();
Now, based on a particular condition, I need to check and do the call to getPersons until the condition is matched or the number of retries (5 retries, 5seconds apart) have finished.
The condition will be
if(personFutures.get().size() != totalPersonsInOrg){
retry(personService.getPersons(), 5, 5)
} else {
return persons
}
I want to use the thenApply and thenCompose to chain these after the first completablefuture.
personFutures.thenApply(persons -> {
if(persons.size() != totalPersonsOrg){
retry(personservice,5,5)
}
})
This is what needs to be changed
private boolean allPersonsFound(String id, int retry, int c
count)
{
if (retry > maxRetries) {
return false;
}
CompletableFuture<List<Persons>> personsFuture = personaService.getPersons();
List<Persons> persons = personsFuture.get();
if (persons.size() != count) {
//add delay of 50ms
return allPersonsFound(id, retry++, count);
}
return true;
}