From 28dfdaba32b6b769f0ef52389793601d2ed843c9 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Tue, 24 Jan 2012 15:03:32 +0100 Subject: [PATCH] Correcting after review --- .../scala/code/akka/docs/future/FutureDocSpec.scala | 10 ++++++++-- akka-docs/scala/futures.rst | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/akka-docs/scala/code/akka/docs/future/FutureDocSpec.scala b/akka-docs/scala/code/akka/docs/future/FutureDocSpec.scala index d1e9532548..175fc08ff5 100644 --- a/akka-docs/scala/code/akka/docs/future/FutureDocSpec.scala +++ b/akka-docs/scala/code/akka/docs/future/FutureDocSpec.scala @@ -131,6 +131,12 @@ class FutureDocSpec extends AkkaSpec { val future2 = future1.filter(_ % 2 == 0) val result = Await.result(future2, 1 second) result must be(4) + + val failedFilter = future1.filter(_ % 2 == 1).recover { + case m: MatchError ⇒ 0 //When filter fails, it will have a MatchError + } + val result2 = Await.result(failedFilter, 1 second) + result2 must be(0) //Can only be 0 when there was a MatchError //#filter } @@ -307,8 +313,8 @@ class FutureDocSpec extends AkkaSpec { def doSomethingOnFailure(t: Throwable) = () //#onComplete future onComplete { - case Right(result) ⇒ doSomethingOnSuccess(result) //Right == Success - case Left(failure) ⇒ doSomethingOnFailure(failure) //Left == Failure + case Right(result) ⇒ doSomethingOnSuccess(result) + case Left(failure) ⇒ doSomethingOnFailure(failure) } //#onComplete Await.result(future, 1 second) must be("foo") diff --git a/akka-docs/scala/futures.rst b/akka-docs/scala/futures.rst index 5d0baa5ca7..c46db30927 100644 --- a/akka-docs/scala/futures.rst +++ b/akka-docs/scala/futures.rst @@ -164,8 +164,8 @@ But it may be faster to use ``traverse`` as it doesn't have to create an interme Then there's a method that's called ``fold`` that takes a start-value, a sequence of ``Future``\s and a function from the type of the start-value and the type of the futures and returns something with the same type as the start-value, -and then applies the function to all elements in the sequence of futures, non-blockingly, -the execution will run on the Thread of the last completing Future in the sequence. +and then applies the function to all elements in the sequence of futures, asynchronously, +the execution will start when the last of the Futures is completed. .. includecode:: code/akka/docs/future/FutureDocSpec.scala :include: fold @@ -180,7 +180,7 @@ as the start-value, you can use ``reduce``, it works like this: .. includecode:: code/akka/docs/future/FutureDocSpec.scala :include: reduce -Same as with ``fold``, the execution will be done by the Thread that completes the last of the Futures, ` +Same as with ``fold``, the execution will be done asynchronously when the last of the Future is completed,` you can also parallelize it by chunking your futures into sub-sequences and reduce them, and then reduce the reduced results again. Callbacks