diff options
author | phaller <hallerp@gmail.com> | 2012-04-15 16:12:04 +0200 |
---|---|---|
committer | phaller <hallerp@gmail.com> | 2012-04-15 16:12:04 +0200 |
commit | 6ecb8263bff937ac545163260c7a4d4c473d996a (patch) | |
tree | 212157c934ad6ac9876a453cead0bcbef1684b4f /src/library/scala/concurrent/Future.scala | |
parent | e4bea920b42eaa526a9e07ad001f17443d6abeba (diff) | |
download | scala-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/scala/concurrent/Future.scala')
-rw-r--r-- | src/library/scala/concurrent/Future.scala | 19 |
1 files changed, 18 insertions, 1 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) }) |