Renaming Future.or to fallbackTo

This commit is contained in:
Viktor Klang 2012-01-31 17:19:38 +01:00
parent 4c2a44ec7a
commit 92426a82d9
6 changed files with 16 additions and 16 deletions

View file

@ -55,11 +55,11 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa
val empty = Promise[String]() val empty = Promise[String]()
val timedOut = Promise.successful[String]("Timedout") val timedOut = Promise.successful[String]("Timedout")
Await.result(failure or timedOut, timeout.duration) must be("Timedout") Await.result(failure fallbackTo timedOut, timeout.duration) must be("Timedout")
Await.result(timedOut or empty, timeout.duration) must be("Timedout") Await.result(timedOut fallbackTo empty, timeout.duration) must be("Timedout")
Await.result(failure or failure or timedOut, timeout.duration) must be("Timedout") Await.result(failure fallbackTo failure fallbackTo timedOut, timeout.duration) must be("Timedout")
intercept[RuntimeException] { intercept[RuntimeException] {
Await.result(failure or otherFailure, timeout.duration) Await.result(failure fallbackTo otherFailure, timeout.duration)
}.getMessage must be("last") }.getMessage must be("last")
} }
} }

View file

@ -442,7 +442,7 @@ sealed trait Future[+T] extends japi.Future[T] with Await.Awaitable[T] {
* Returns a new Future that will either hold the successful value of this Future, * Returns a new Future that will either hold the successful value of this Future,
* or, it this Future fails, it will hold the result of "that" Future. * or, it this Future fails, it will hold the result of "that" Future.
*/ */
def or[U >: T](that: Future[U]): Future[U] = { def fallbackTo[U >: T](that: Future[U]): Future[U] = {
val p = Promise[U]() val p = Promise[U]()
onComplete { onComplete {
case r @ Right(_) p complete r case r @ Right(_) p complete r

View file

@ -382,7 +382,7 @@ public class FutureDocTestBase {
} }
{ {
//#or //#fallback-to
Future<String> future1 = Future<String> future1 =
Futures.failed(new IllegalStateException("OHNOES1"), system.dispatcher()); Futures.failed(new IllegalStateException("OHNOES1"), system.dispatcher());
Future<String> future2 = Future<String> future2 =
@ -390,10 +390,10 @@ public class FutureDocTestBase {
Future<String> future3 = Future<String> future3 =
Futures.successful("bar", system.dispatcher()); Futures.successful("bar", system.dispatcher());
Future<String> future4 = Future<String> future4 =
future1.or(future2).or(future3); // Will have "bar" in this case future1.fallbackTo(future2).fallbackTo(future3); // Will have "bar" in this case
String result = Await.result(future4, Duration.create(1, SECONDS)); String result = Await.result(future4, Duration.create(1, SECONDS));
assertEquals("bar", result); assertEquals("bar", result);
//#or //#fallback-to
} }
} }

View file

@ -179,11 +179,11 @@ For this Akka supports ``onComplete``, ``onSuccess`` and ``onFailure``, of which
Auxiliary methods Auxiliary methods
----------------- -----------------
``Future`` ``or`` combines 2 Futures into a new ``Future``, and will hold the successful value of the second ``Future` ``Future`` ``fallbackTo`` combines 2 Futures into a new ``Future``, and will hold the successful value of the second ``Future`
if the first ``Future`` fails. if the first ``Future`` fails.
.. includecode:: code/akka/docs/future/FutureDocTestBase.java .. includecode:: code/akka/docs/future/FutureDocTestBase.java
:include: or :include: fallback-to
You can also combine two Futures into a new ``Future`` that will hold a tuple of the two Futures successful results, You can also combine two Futures into a new ``Future`` that will hold a tuple of the two Futures successful results,
using the ``zip`` operation. using the ``zip`` operation.

View file

@ -275,13 +275,13 @@ class FutureDocSpec extends AkkaSpec {
Await.result(future3, 1 second) must be("foo bar") Await.result(future3, 1 second) must be("foo bar")
} }
"demonstrate usage of or" in { "demonstrate usage of fallbackTo" in {
val future1 = Future { "foo" } val future1 = Future { "foo" }
val future2 = Future { "bar" } val future2 = Future { "bar" }
val future3 = Future { "pigdog" } val future3 = Future { "pigdog" }
//#or //#fallback-to
val future4 = future1 or future2 or future3 val future4 = future1 fallbackTo future2 fallbackTo future3
//#or //#fallback-to
Await.result(future4, 1 second) must be("foo") Await.result(future4, 1 second) must be("foo")
} }

View file

@ -201,11 +201,11 @@ For this Akka supports ``onComplete``, ``onSuccess`` and ``onFailure``, of which
Auxiliary methods Auxiliary methods
----------------- -----------------
``Future`` ``or`` combines 2 Futures into a new ``Future``, and will hold the successful value of the second ``Future` ``Future`` ``fallbackTo`` combines 2 Futures into a new ``Future``, and will hold the successful value of the second ``Future`
if the first ``Future`` fails. if the first ``Future`` fails.
.. includecode:: code/akka/docs/future/FutureDocSpec.scala .. includecode:: code/akka/docs/future/FutureDocSpec.scala
:include: or :include: fallback-to
You can also combine two Futures into a new ``Future`` that will hold a tuple of the two Futures successful results, You can also combine two Futures into a new ``Future`` that will hold a tuple of the two Futures successful results,
using the ``zip`` operation. using the ``zip`` operation.