summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/concurrent/Awaitable.scala9
-rw-r--r--src/library/scala/concurrent/Future.scala23
-rw-r--r--src/library/scala/concurrent/impl/ExecutionContextImpl.scala2
-rw-r--r--src/library/scala/concurrent/package.scala10
4 files changed, 15 insertions, 29 deletions
diff --git a/src/library/scala/concurrent/Awaitable.scala b/src/library/scala/concurrent/Awaitable.scala
index 052e6e2366..99bdfbc5a9 100644
--- a/src/library/scala/concurrent/Awaitable.scala
+++ b/src/library/scala/concurrent/Awaitable.scala
@@ -10,18 +10,23 @@ package scala.concurrent
-import scala.annotation.implicitNotFound
import scala.concurrent.util.Duration
trait Awaitable[+T] {
+ /**
+ * Should throw [[scala.concurrent.TimeoutException]] if it times out
+ * This method should not be called directly.
+ */
+ @throws(classOf[TimeoutException])
def ready(atMost: Duration)(implicit permit: CanAwait): this.type
/**
- * Throws exceptions if cannot produce a T within the specified time
+ * Throws exceptions if it cannot produce a T within the specified time.
* This method should not be called directly.
*/
+ @throws(classOf[Exception])
def result(atMost: Duration)(implicit permit: CanAwait): T
}
diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala
index 5f703ac23b..5bc9ad783f 100644
--- a/src/library/scala/concurrent/Future.scala
+++ b/src/library/scala/concurrent/Future.scala
@@ -82,7 +82,6 @@ import scala.collection.generic.CanBuildFrom
* }}}
*/
trait Future[+T] extends Awaitable[T] {
-self =>
/* Callbacks */
@@ -132,7 +131,7 @@ self =>
/** Creates a new promise.
*/
- def newPromise[S]: Promise[S]
+ protected def newPromise[S]: Promise[S]
/** Returns whether the future has already been completed with
* a value or an exception.
@@ -168,14 +167,11 @@ self =>
* and throws a corresponding exception if the original future fails.
*/
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]
onComplete {
case Left(t) => p success t
- case Right(v) => p failure noSuchElem(v)
+ case Right(v) => p failure (new NoSuchElementException("Future.failed not completed with a throwable. Instead completed with: " + v))
}
p.future
@@ -411,21 +407,16 @@ self =>
* {{{
* val f = future { sys.error("failed") }
* val g = future { 5 }
- * val h = f orElse g
+ * val h = f fallbackTo g
* await(h, 0) // evaluates to 5
* }}}
*/
def fallbackTo[U >: T](that: Future[U]): Future[U] = {
val p = newPromise[U]
-
onComplete {
- case Left(t) => that onComplete {
- case Left(_) => p failure t
- case Right(v) => p success v
- }
- case Right(v) => p success v
+ case r @ Right(_) ⇒ p complete r
+ case _ ⇒ p completeWith that
}
-
p.future
}
@@ -497,14 +488,14 @@ self =>
* }}}
*/
def either[U >: T](that: Future[U]): Future[U] = {
- val p = self.newPromise[U]
+ val p = newPromise[U]
val completePromise: PartialFunction[Either[Throwable, U], _] = {
case Left(t) => p tryFailure t
case Right(v) => p trySuccess v
}
- self onComplete completePromise
+ this onComplete completePromise
that onComplete completePromise
p.future
diff --git a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
index 52c834359d..c5062267dc 100644
--- a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
+++ b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
@@ -84,7 +84,7 @@ private[scala] class ExecutionContextImpl(es: AnyRef) extends ExecutionContext w
}
-object ExecutionContextImpl {
+private[concurrent] object ExecutionContextImpl {
private[concurrent] def currentExecutionContext: ThreadLocal[ExecutionContext] = new ThreadLocal[ExecutionContext] {
override protected def initialValue = null
diff --git a/src/library/scala/concurrent/package.scala b/src/library/scala/concurrent/package.scala
index e2ae17498f..b06c6f3c63 100644
--- a/src/library/scala/concurrent/package.scala
+++ b/src/library/scala/concurrent/package.scala
@@ -31,16 +31,6 @@ package concurrent {
def result[T](awaitable: Awaitable[T], atMost: Duration): T = awaitable.result(atMost)
}
- /** A timeout exception.
- *
- * Futures are failed with a timeout exception when their timeout expires.
- *
- * Each timeout exception contains an origin future which originally timed out.
- */
- class FutureTimeoutException(origin: Future[_], message: String) extends TimeoutException(message) {
- def this(origin: Future[_]) = this(origin, "Future timed out.")
- }
-
final class DurationOps private[concurrent] (x: Int) {
// TODO ADD OTHERS
def ns = util.Duration.fromNanos(0)