Last active
January 15, 2018 08:43
-
-
Save JohnMurray/d43be3d683d4496b6663c5a9ef2da9bb to your computer and use it in GitHub Desktop.
Simple retries with future-based networking code in Scala (with back-off)
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 networkRequestWithRetries()(implicit as: ActorSystem): Future[String] = { | |
networkRequest().recoverWith { | |
case NetworkException => | |
println("retrying") | |
after(2.seconds, as.scheduler, global, Future.successful(1)).flatMap { _ => | |
networkRequestWithRetries() | |
} | |
case t: Throwable => throw t | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment