I am using Failsafe
framework (link) to execute a method. My use case is to execute a void
method x number of times and return success
or failure
based on the execution result. Below is how my (pseudo) code looks like:
public void methodThatNeedsToExecute(){..}
public String failsafeWrapper(){
RetryPolicy<String> retryPolicy = new RetryPolicy<>().withMaxRetries(50);
return Failsafe.with(retryPolicy)
.onSuccess(return "success") // how to do this?
.onFailure(return "failure") //how to do this?
.get(() -> methodThatNeedsToExecute()); //this won't work
}
I can use run
method of Failsafe
to execute my void method (i.e. methodThatNeedsToExecute()
). However, how can I return something based on how execution with retries goes?