summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraleksandar <aleksandar@lampmac14.epfl.ch>2012-01-27 10:53:17 +0100
committeraleksandar <aleksandar@lampmac14.epfl.ch>2012-01-27 10:53:17 +0100
commit6a8db335b0312342f95df9dc87fcc016fed3a463 (patch)
tree468d4a79814227008aebfa4ec5800805c856937a
parent85daadef89a9ed5c3901a5822221366ee6746d49 (diff)
downloadscala-6a8db335b0312342f95df9dc87fcc016fed3a463.tar.gz
scala-6a8db335b0312342f95df9dc87fcc016fed3a463.tar.bz2
scala-6a8db335b0312342f95df9dc87fcc016fed3a463.zip
Change the implementation of the future failed projection.
-rw-r--r--src/library/scala/concurrent/Future.scala31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala
index 2ad24c052d..29b17cf70a 100644
--- a/src/library/scala/concurrent/Future.scala
+++ b/src/library/scala/concurrent/Future.scala
@@ -149,27 +149,18 @@ self =>
* Blocking on this future returns a value if the original future is completed with an exception
* and throws a corresponding exception if the original future fails.
*/
- def failed: Future[Throwable] = new Future[Throwable] {
- def newPromise[S]: Promise[S] = self.newPromise
- def onComplete[U](func: Either[Throwable, Throwable] => U) = {
- self.onComplete {
- case Left(t) => func(Right(t))
- case Right(v) => func(Left(noSuchElem(v))) // do nothing
- }
- this
- }
- def await(atMost: Duration)(implicit canawait: CanAwait): Throwable = {
- var t: Throwable = null
- try {
- val res = self.await(atMost)
- t = noSuchElem(res)
- } catch {
- case t: Throwable => return t
- }
- throw t
- }
- private def noSuchElem(v: T) =
+ def failed: Future[Throwable] = {
+ def noSuchElem(v: T) =
new NoSuchElementException("Future.failed not completed with a throwable. Instead completed with: " + v)
+
+ val p = newPromise[Throwable]
+
+ this onComplete {
+ case Left(t) => p success t
+ case Right(v) => p failure noSuchElem(v)
+ }
+
+ p.future
}