Permalink
Browse files

SI-6913 Fixing semantics of Future fallbackTo to be according to docs

  • Loading branch information...
1 parent 7c1d114 commit 70634395a4ea6e05877704e655a5870692581ebc @heathermiller heathermiller committed with phaller Nov 22, 2013
@@ -384,7 +384,10 @@ trait Future[+T] extends Awaitable[T] {
val p = Promise[U]()
onComplete {
case s @ Success(_) => p complete s
- case _ => p completeWith that
+ case f @ Failure(_) => that onComplete {
+ case s2 @ Success(_) => p complete s2
+ case _ => p complete f // Use the first failure as the failure
+ }
}
p.future
}
@@ -38,10 +38,10 @@ object PromiseTests extends MinimalScalaTest {
Await.result(failure fallbackTo timedOut, defaultTimeout) mustBe ("Timedout")
Await.result(timedOut fallbackTo empty, defaultTimeout) mustBe ("Timedout")
- Await.result(failure fallbackTo failure fallbackTo timedOut, defaultTimeout) mustBe ("Timedout")
+ Await.result(otherFailure fallbackTo failure fallbackTo timedOut, defaultTimeout) mustBe ("Timedout")
intercept[RuntimeException] {
Await.result(failure fallbackTo otherFailure, defaultTimeout)
- }.getMessage mustBe ("last")
+ }.getMessage mustBe ("br0ken")
}
}
@@ -344,8 +344,8 @@ def testTransformFailure(): Unit = once {
def testFallbackToFailure(): Unit = once {
done =>
val cause = new Exception
- val f = future { sys.error("failed") }
- val g = future { throw cause }
+ val f = future { throw cause }
+ val g = future { sys.error("failed") }
val h = f fallbackTo g
h onSuccess { case _ => done(false) }

0 comments on commit 7063439

Please sign in to comment.