Skip to content

Instantly share code, notes, and snippets.

@jamesgolick
Created October 10, 2010 04:07
Show Gist options
  • Select an option

  • Save jamesgolick/618930 to your computer and use it in GitHub Desktop.

Select an option

Save jamesgolick/618930 to your computer and use it in GitHub Desktop.
def apply[A](attempt: Int)(f: Conn => A): A = {
val node = nextLiveNode()
val pool = node.pool
val connection = pool.borrow()
try {
val value = f(connection)
pool.giveBack(connection)
value
} catch {
case e: Throwable if attempt == maxRetries => pool.invalidate(connection); throw e
case e: Throwable if canRecover(e) => pool.invalidate(connection); failNode(node); apply(attempt + 1)(f)
case e: Throwable => pool.invalidate(connection); throw e
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment