From bc1f7565b7ff175c4bf6e9c08a8d30f9c1983cc8 Mon Sep 17 00:00:00 2001 From: Derek Williams Date: Sat, 6 Aug 2011 13:32:03 -0600 Subject: [PATCH] Fixed race in Future.await, and minor changes to Future.result and Future.exception --- akka-actor/src/main/scala/akka/dispatch/Future.scala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/akka-actor/src/main/scala/akka/dispatch/Future.scala b/akka-actor/src/main/scala/akka/dispatch/Future.scala index 3b8be4bb94..cfd729a25e 100644 --- a/akka-actor/src/main/scala/akka/dispatch/Future.scala +++ b/akka-actor/src/main/scala/akka/dispatch/Future.scala @@ -407,16 +407,16 @@ sealed trait Future[+T] extends japi.Future[T] { * Returns the successful result of this Future if it exists. */ final def result: Option[T] = value match { - case Some(r) ⇒ r.right.toOption - case _ ⇒ None + case Some(Right(r)) ⇒ Some(r) + case _ ⇒ None } /** * Returns the contained exception of this Future if it exists. */ final def exception: Option[Throwable] = value match { - case Some(r) ⇒ r.left.toOption - case _ ⇒ None + case Some(Left(e)) ⇒ Some(e) + case _ ⇒ None } /** @@ -740,7 +740,7 @@ class DefaultPromise[T](val timeout: Timeout)(implicit val dispatcher: MessageDi val ms = NANOS.toMillis(waitTimeNanos) val ns = (waitTimeNanos % 1000000l).toInt //As per object.wait spec val start = currentTimeInNanos - try { ref.synchronized { ref.wait(ms, ns) } } catch { case e: InterruptedException ⇒ } + try { ref.synchronized { if (value.isEmpty) ref.wait(ms, ns) } } catch { case e: InterruptedException ⇒ } awaitUnsafe(waitTimeNanos - (currentTimeInNanos - start)) } else {