Skip to content

Instantly share code, notes, and snippets.

@allenktv
Last active September 21, 2015 22:46
Show Gist options
  • Save allenktv/e3ab30f83995f9eaf6b0 to your computer and use it in GitHub Desktop.
Save allenktv/e3ab30f83995f9eaf6b0 to your computer and use it in GitHub Desktop.
Allows retry of a function, and retries it if null is returned
public class RetryRunner<T> {
public T runWithRetries(IRetry<T> retry, int numOfRetries) {
for (int i = 0; i <= numOfRetries; i++) {
T value = retry.run();
if (value != null) {
return value;
}
}
return null;
}
}
public static interface IRetry<T> {
T run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment