Skip to content

Instantly share code, notes, and snippets.

@cshijiel
Created November 6, 2019 02:59
Show Gist options
  • Save cshijiel/c8021da3ab8680e7b5aabc033c54a472 to your computer and use it in GitHub Desktop.
Save cshijiel/c8021da3ab8680e7b5aabc033c54a472 to your computer and use it in GitHub Desktop.
public <T> void retryAction(Supplier<T> task, Predicate<T> predicate, Consumer<T> after, int retryTimes) {
for (int i = 0; i < retryTimes; i++) {
T res = task.get();
log.info("retry result {}", res);
if (predicate.test(res)) {
after.accept(res);
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment