summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorphaller <hallerp@gmail.com>2012-04-15 16:12:04 +0200
committerphaller <hallerp@gmail.com>2012-04-15 16:12:04 +0200
commit6ecb8263bff937ac545163260c7a4d4c473d996a (patch)
tree212157c934ad6ac9876a453cead0bcbef1684b4f /src/library
parente4bea920b42eaa526a9e07ad001f17443d6abeba (diff)
downloadscala-6ecb8263bff937ac545163260c7a4d4c473d996a.tar.gz
scala-6ecb8263bff937ac545163260c7a4d4c473d996a.tar.bz2
scala-6ecb8263bff937ac545163260c7a4d4c473d996a.zip
Clean ups in futures based on review by @heathermiller and review by @viktorklang
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/concurrent/Future.scala19
-rw-r--r--src/library/scala/concurrent/impl/ExecutionContextImpl.scala10
-rw-r--r--src/library/scala/concurrent/impl/Future.scala25
3 files changed, 25 insertions, 29 deletions
diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala
index f5f0c5cdfd..9aaf05dbd6 100644
--- a/src/library/scala/concurrent/Future.scala
+++ b/src/library/scala/concurrent/Future.scala
@@ -426,13 +426,30 @@ trait Future[+T] extends Awaitable[T] {
* that conforms to `S`'s erased type or a `ClassCastException` otherwise.
*/
def mapTo[S](implicit m: Manifest[S]): Future[S] = {
+ import java.{ lang => jl }
+ val toBoxed = Map[Class[_], Class[_]](
+ classOf[Boolean] -> classOf[jl.Boolean],
+ classOf[Byte] -> classOf[jl.Byte],
+ classOf[Char] -> classOf[jl.Character],
+ classOf[Short] -> classOf[jl.Short],
+ classOf[Int] -> classOf[jl.Integer],
+ classOf[Long] -> classOf[jl.Long],
+ classOf[Float] -> classOf[jl.Float],
+ classOf[Double] -> classOf[jl.Double],
+ classOf[Unit] -> classOf[scala.runtime.BoxedUnit]
+ )
+
+ def boxedType(c: Class[_]): Class[_] = {
+ if (c.isPrimitive) toBoxed(c) else c
+ }
+
val p = newPromise[S]
onComplete {
case l: Left[Throwable, _] => p complete l.asInstanceOf[Either[Throwable, S]]
case Right(t) =>
p complete (try {
- Right(impl.Future.boxedType(m.erasure).cast(t).asInstanceOf[S])
+ Right(boxedType(m.erasure).cast(t).asInstanceOf[S])
} catch {
case e: ClassCastException => Left(e)
})
diff --git a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
index 2b929d91ab..ad98331241 100644
--- a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
+++ b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala
@@ -93,12 +93,10 @@ private[scala] class ExecutionContextImpl(es: AnyRef) extends ExecutionContext w
}
def reportFailure(t: Throwable) = t match {
- /*TODO: clarify that resolver should wrap Errors, in which case we do not want
- Error to be re-thrown here */
- case e: Error => throw e // rethrow serious errors
- case t =>
- //println(t.toString)
- t.printStackTrace()
+ // `Error`s are currently wrapped by `resolver`.
+ // Also, re-throwing `Error`s here causes an exception handling test to fail.
+ //case e: Error => throw e
+ case t => t.printStackTrace()
}
}
diff --git a/src/library/scala/concurrent/impl/Future.scala b/src/library/scala/concurrent/impl/Future.scala
index 9743c37403..548524c9fe 100644
--- a/src/library/scala/concurrent/impl/Future.scala
+++ b/src/library/scala/concurrent/impl/Future.scala
@@ -42,20 +42,6 @@ private[concurrent] trait Future[+T] extends scala.concurrent.Future[T] with Awa
}
object Future {
- import java.{ lang => jl }
-
- private val toBoxed = Map[Class[_], Class[_]](
- classOf[Boolean] -> classOf[jl.Boolean],
- classOf[Byte] -> classOf[jl.Byte],
- classOf[Char] -> classOf[jl.Character],
- classOf[Short] -> classOf[jl.Short],
- classOf[Int] -> classOf[jl.Integer],
- classOf[Long] -> classOf[jl.Long],
- classOf[Float] -> classOf[jl.Float],
- classOf[Double] -> classOf[jl.Double],
- classOf[Unit] -> classOf[scala.runtime.BoxedUnit]
- )
-
/** Wraps a block of code into an awaitable object. */
private[concurrent] def body2awaitable[T](body: =>T) = new Awaitable[T] {
def ready(atMost: Duration)(implicit permit: CanAwait) = {
@@ -65,23 +51,18 @@ object Future {
def result(atMost: Duration)(implicit permit: CanAwait) = body
}
- def boxedType(c: Class[_]): Class[_] = {
- if (c.isPrimitive) toBoxed(c) else c
- }
-
def apply[T](body: =>T)(implicit executor: ExecutionContext): Future[T] = {
val promise = new Promise.DefaultPromise[T]()
- //TODO: shouldn't the following be:
- //dispatchFuture(executor, () => { promise complete Right(body) })
-
+ //TODO: use `dispatchFuture`?
executor.execute(new Runnable {
def run = {
promise complete {
try {
Right(body)
} catch {
- case e =>
+ case NonFatal(e) =>
+ // Commenting out reporting for now, since it produces too much output in the tests
//executor.reportFailure(e)
scala.concurrent.resolver(e)
}