Last active
September 21, 2015 22:46
-
-
Save allenktv/e3ab30f83995f9eaf6b0 to your computer and use it in GitHub Desktop.
Allows retry of a function, and retries it if null is returned
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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