Created
March 14, 2011 21:46
-
-
Save p3t0r/869950 to your computer and use it in GitHub Desktop.
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
trait Retrying[T] extends Repository[T] { | |
abstract override def withConnection(f: (Connection => Option[T])): Option[T] = retry(f) | |
private def retry(f: (Connection => Option[T]), times: Int = 3): Option[T] = { | |
try { | |
println("number of tries left: %d".format(times)) | |
super.withConnection(f) | |
} catch { | |
case _ if times == 0 => None | |
case _ => retry(f, times - 1) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment