diff --git a/akka-actor/src/main/scala/akka/dispatch/Future.scala b/akka-actor/src/main/scala/akka/dispatch/Future.scala index 0d3bfc9a31..ab0e064c4a 100644 --- a/akka-actor/src/main/scala/akka/dispatch/Future.scala +++ b/akka-actor/src/main/scala/akka/dispatch/Future.scala @@ -146,6 +146,8 @@ sealed trait Future[T] { def result: Option[T] = value flatMap (_.right.toOption) + def awaitResult: Option[Either[Throwable, T]] + /** * Returns the result of the Future if one is available within the specified time, * if the time left on the future is less than the specified time, the time left on the future will be used instead @@ -209,6 +211,14 @@ class DefaultCompletableFuture[T](timeout: Long) extends CompletableFuture[T] { } } + def awaitResult: Option[Either[Throwable, T]] = try { + _lock.lock + awaitUnsafe(timeoutInNanos - (currentTimeInNanos - _startTimeInNanos)) + _value + } finally { + _lock.unlock + } + def resultWithin(time: Long, unit: TimeUnit): Option[Either[Throwable, T]] = try { _lock.lock awaitUnsafe(unit.toNanos(time).min(timeoutInNanos - (currentTimeInNanos - _startTimeInNanos)))