Skip to content

Instantly share code, notes, and snippets.

@johntbush
Created March 4, 2015 06:52
Show Gist options
  • Save johntbush/5efb5f27dde0c51747bc to your computer and use it in GitHub Desktop.
Save johntbush/5efb5f27dde0c51747bc to your computer and use it in GitHub Desktop.
retry
@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