From cbad136be350087ebb29b9a36c1da893bbb18ec9 Mon Sep 17 00:00:00 2001 From: Aleksandar Prokopec Date: Wed, 7 Dec 2011 16:52:08 +0100 Subject: Minor changes with the docs. --- src/library/scala/concurrent/Future.scala | 22 +++++++++++++--------- src/library/scala/concurrent/Promise.scala | 13 +++++++------ 2 files changed, 20 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala index 5f64c2fc1a..9c1b8b4cd1 100644 --- a/src/library/scala/concurrent/Future.scala +++ b/src/library/scala/concurrent/Future.scala @@ -38,12 +38,12 @@ import java.util.concurrent.atomic.{ AtomicReferenceFieldUpdater, AtomicInteger, * @define caughtThrowables * The future may contain a throwable object and this means that the future failed. * Futures obtained through combinators have the same exception as the future they were obtained from. - * The following throwable objects are not caught by the future: + * The following throwable objects are not contained in the future: * - Error - errors are not contained within futures - * - scala.util.control.ControlException - not contained within futures + * - scala.util.control.ControlThrowable - not contained within futures * - InterruptedException - not contained within futures * - * Instead, the future is completed with a NoSuchElementException with one of the exceptions above + * Instead, the future is completed with a ExecutionException with one of the exceptions above * as the cause. * * @define forComprehensionExamples @@ -59,7 +59,7 @@ import java.util.concurrent.atomic.{ AtomicReferenceFieldUpdater, AtomicInteger, * }}} * * is translated to: - * + * * {{{ * f flatMap { (x: Int) => g map { (y: Int) => x + y } } * }}} @@ -85,8 +85,8 @@ self => } /** When this future is completed with a failure (i.e. with a throwable), - * apply the provided function to the throwable. - * + * apply the provided callback to the throwable. + * * $caughtThrowables * * If the future has already been completed with a failure, @@ -98,9 +98,8 @@ self => * * $multipleCallbacks */ - def onFailure[U](callback: Throwable => U): this.type = onComplete { - case Left(te: FutureTimeoutException) => callback(te) - case Left(t) if isFutureThrowable(t) => callback(t) + def onFailure[U](callback: PartialFunction[Throwable, U]): this.type = onComplete { + case Left(t) if t.isInstanceOf[FutureTimeoutException] || isFutureThrowable(t) => if (callback.isDefinedAt(t)) callback(t) case Right(v) => // do nothing } @@ -161,6 +160,9 @@ self => /* Projections */ + /** A failed projection of the future. + * + */ def failed: Future[Throwable] = new Future[Throwable] { def executionContext = self.executionContext def onComplete[U](func: Either[Throwable, Throwable] => U) = { @@ -182,6 +184,8 @@ self => new NoSuchElementException("Future.failed not completed with a throwable. Instead completed with: " + v) } + /** A timed out projection of the future. + */ def timedout: Future[FutureTimeoutException] = new Future[FutureTimeoutException] { def executionContext = self.executionContext def onComplete[U](func: Either[Throwable, FutureTimeoutException] => U) = { diff --git a/src/library/scala/concurrent/Promise.scala b/src/library/scala/concurrent/Promise.scala index 898344cb66..ff72dee4b9 100644 --- a/src/library/scala/concurrent/Promise.scala +++ b/src/library/scala/concurrent/Promise.scala @@ -17,12 +17,14 @@ import scala.util.Timeout /** Promise is an object which can be completed with a value or failed * with an exception. * - * A promise is assigned a timeout when created. After the timeout expires, - * the promise will be failed with a TimeoutException. - * * @define promiseCompletion * If the promise has already been fulfilled, failed or has timed out, * calling this method will throw an IllegalStateException. + * + * @define allowedThrowables + * If the throwable used to fail this promise is an error, a control exception + * or an interrupted exception, it will be wrapped as a cause within an + * ExecutionException which will fail the promise. */ trait Promise[T] { @@ -42,13 +44,12 @@ trait Promise[T] { * * @param t The throwable to complete the promise with. * + * $allowedThrowables + * * $promiseCompletion */ def fail(t: Throwable): Unit - /** The timeout for this promise. - */ - def timeout: Timeout } -- cgit v1.2.3