Stream supervision doc clarification #23376

This commit is contained in:
Johan Andrén 2017-07-26 16:23:46 +02:00 committed by GitHub
parent 8eabc685dc
commit 407131cb4e
34 changed files with 509 additions and 193 deletions

View file

@ -89,4 +89,57 @@ class FlowErrorDocSpec extends AkkaSpec {
Await.result(result, 3.seconds) should be(Vector(0, 1, 4, 0, 5, 12))
}
"demonstrate recover" in {
implicit val materializer = ActorMaterializer()
//#recover
Source(0 to 6).map(n =>
if (n < 5) n.toString
else throw new RuntimeException("Boom!")
).recover {
case _: RuntimeException => "stream truncated"
}.runForeach(println)
//#recover
/*
Output:
//#recover-output
0
1
2
3
4
stream truncated
//#recover-output
*/
}
"demonstrate recoverWithRetries" in {
implicit val materializer = ActorMaterializer()
//#recoverWithRetries
val planB = Source(List("five", "six", "seven", "eight"))
Source(0 to 10).map(n =>
if (n < 5) n.toString
else throw new RuntimeException("Boom!")
).recoverWithRetries(attempts = 1, {
case _: RuntimeException => planB
}).runForeach(println)
//#recoverWithRetries
/*
Output:
//#recoverWithRetries-output
0
1
2
3
4
five
six
seven
eight
//#recoverWithRetries-output
*/
}
}