Created
April 3, 2014 08:37
-
-
Save ElectricCoffee/9950655 to your computer and use it in GitHub Desktop.
Basic method that lets you attempt to get a result up to a given number of times
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
def attempt[T,E <: Exception](attempts: Int, subject: String, failedMessage: String, exception: E, failCondition: T => Boolean)(body: => T): T = { | |
val i = body | |
if(failCondition(i) && attempts != 0) { | |
println(s"Subject: $subject") | |
println(s"Message: $failedMessage") | |
println(s"Attempts left: $attempts") | |
// do something with the exception | |
attempt(attempts - 1, subject, failedMessage, exception, failCondition)(body) | |
} | |
else i | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment