Added retry pattern #22276 (#23997)

This commit is contained in:
Daniel Kalman 2018-03-26 14:56:20 +03:00 committed by Patrik Nordwall
parent 46c662965f
commit 86e44167f3
7 changed files with 245 additions and 8 deletions

View file

@ -430,6 +430,27 @@ class FutureDocSpec extends AkkaSpec {
intercept[IllegalStateException] { Await.result(result, 2 second) }
}
"demonstrate pattern.retry" in {
//#retry
implicit val scheduler = system.scheduler
//Given some future that will succeed eventually
@volatile var failCount = 0
def attempt() = {
if (failCount < 5) {
failCount += 1
Future.failed(new IllegalStateException(failCount.toString))
} else Future.successful(5)
}
//Return a new future that will retry up to 10 times
val retried = akka.pattern.retry(
attempt,
10,
100 milliseconds)
//#retry
Await.result(retried, 1 second) should ===(5)
}
"demonstrate context.dispatcher" in {
//#context-dispatcher
class A extends Actor {