Skip to content

Commit

Permalink
SI-6913 Fixing semantics of Future fallbackTo to be according to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
heathermiller authored and phaller committed Dec 5, 2013
1 parent 7c1d114 commit 7063439
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/library/scala/concurrent/Future.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions test/files/jvm/future-spec/PromiseTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

}
Expand Down
4 changes: 2 additions & 2 deletions test/files/jvm/scala-concurrent-tck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit 7063439

Please sign in to comment.