Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @tailrec
- def retryOn[T](thCls: Class[_ <: Throwable], maxTimes: Int, delayBetweenRetries: Int = 0, onRetry: => Unit = {})(block: => T): T = {
- try block
- catch {
- case t: Throwable if thCls.isInstance(t) && maxTimes > 0 =>
- onRetry
- Thread.sleep(delayBetweenRetries)
- retryOn(thCls, maxTimes - 1, delayBetweenRetries, onRetry)(block)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement