summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Haller <hallerp@gmail.com>2011-12-07 18:25:54 +0100
committerPhilipp Haller <hallerp@gmail.com>2011-12-07 18:25:54 +0100
commit14c98635e3a313b383ad16efc0f6140ba7aaa670 (patch)
treeb0433202cc9a6a45419804f22b9a7539327f287f
parent2c01191b99d912f99a7d50be693d09406761a94c (diff)
parentc9d10fc4f3d50892890b96db2fbb790457d15f43 (diff)
downloadscala-14c98635e3a313b383ad16efc0f6140ba7aaa670.tar.gz
scala-14c98635e3a313b383ad16efc0f6140ba7aaa670.tar.bz2
scala-14c98635e3a313b383ad16efc0f6140ba7aaa670.zip
Fix merge conflict
-rw-r--r--src/library/scala/concurrent/Future.scala22
-rw-r--r--src/library/scala/concurrent/Promise.scala10
2 files changed, 20 insertions, 12 deletions
diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala
index 8394c0b7aa..a59eb667ee 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
}
@@ -149,6 +148,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) = {
@@ -169,6 +171,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 33953f2fca..b841ea16f0 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,6 +44,8 @@ trait Promise[T] {
*
* @param t The throwable to complete the promise with.
*
+ * $allowedThrowables
+ *
* $promiseCompletion
*/
def break(t: Throwable): Unit