Created
March 4, 2015 06:52
-
-
Save johntbush/5efb5f27dde0c51747bc to your computer and use it in GitHub Desktop.
retry
This file contains 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
@annotation.tailrec | |
final def retry[T](n: Int)(fn: => T): T = { | |
util.Try { fn } match { | |
case util.Success(x) => x | |
case _ if n > 1 => retry(n - 1)(fn) | |
case util.Failure(e) => throw e | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment