diff options
author | phaller <hallerp@gmail.com> | 2012-05-10 17:25:39 +0200 |
---|---|---|
committer | phaller <hallerp@gmail.com> | 2012-05-10 17:25:39 +0200 |
commit | 3fdc05278918df210b0c2b859f4588e14051bd41 (patch) | |
tree | 6b978fe63e99fb094ac47e4e91714b60a8ea7772 /src/library | |
parent | b0e85333a286075882352f66e59e5aa3f287e62e (diff) | |
download | scala-3fdc05278918df210b0c2b859f4588e14051bd41.tar.gz scala-3fdc05278918df210b0c2b859f4588e14051bd41.tar.bz2 scala-3fdc05278918df210b0c2b859f4588e14051bd41.zip |
Move resolver and resolveEither to impl.Promise
Diffstat (limited to 'src/library')
6 files changed, 28 insertions, 42 deletions
diff --git a/src/library/scala/concurrent/ConcurrentPackageObject.scala b/src/library/scala/concurrent/ConcurrentPackageObject.scala index a3d985733e..c3c329121c 100644 --- a/src/library/scala/concurrent/ConcurrentPackageObject.scala +++ b/src/library/scala/concurrent/ConcurrentPackageObject.scala @@ -11,7 +11,6 @@ package scala.concurrent import java.util.concurrent.{ Executors, ExecutorService, ThreadFactory } import scala.concurrent.forkjoin.{ ForkJoinPool, ForkJoinWorkerThread } import scala.concurrent.util.Duration -import ConcurrentPackageObject._ import language.implicitConversions @@ -36,19 +35,6 @@ abstract class ConcurrentPackageObject { case _ => true } - private[concurrent] def resolveEither[T](source: Either[Throwable, T]): Either[Throwable, T] = source match { - case Left(t) => resolver(t) - case _ => source - } - - private[concurrent] def resolver[T](throwable: Throwable): Either[Throwable, T] = throwable match { - case t: scala.runtime.NonLocalReturnControl[_] => Right(t.value.asInstanceOf[T]) - case t: scala.util.control.ControlThrowable => Left(new ExecutionException("Boxed ControlThrowable", t)) - case t: InterruptedException => Left(new ExecutionException("Boxed InterruptedException", t)) - case e: Error => Left(new ExecutionException("Boxed Error", e)) - case t => Left(t) - } - /* concurrency constructs */ /** Starts an asynchronous computation and returns a `Future` object with the result of that computation. @@ -102,18 +88,3 @@ abstract class ConcurrentPackageObject { @inline implicit final def int2durationops(x: Int): DurationOps = new DurationOps(x) } - -private[concurrent] object ConcurrentPackageObject { - // TODO, docs, return type - // Note that having this in the package object led to failures when - // compiling a subset of sources; it seems that the wildcard is not - // properly handled, and you get messages like "type _$1 defined twice". - // This is consistent with other package object breakdowns. - // private val resolverFunction: PartialFunction[Throwable, Either[Throwable, _]] = { - // case t: scala.runtime.NonLocalReturnControl[_] => Right(t.value) - // case t: scala.util.control.ControlThrowable => Left(new ExecutionException("Boxed ControlThrowable", t)) - // case t: InterruptedException => Left(new ExecutionException("Boxed InterruptedException", t)) - // case e: Error => Left(new ExecutionException("Boxed Error", e)) - // case t => Left(t) - // } -} diff --git a/src/library/scala/concurrent/ExecutionContext.scala b/src/library/scala/concurrent/ExecutionContext.scala index 4666674b5b..d2a2d5e8a8 100644 --- a/src/library/scala/concurrent/ExecutionContext.scala +++ b/src/library/scala/concurrent/ExecutionContext.scala @@ -54,8 +54,7 @@ object ExecutionContext { def fromExecutor(e: Executor, reporter: Throwable => Unit = defaultReporter): ExecutionContext with Executor = new impl.ExecutionContextImpl(e, reporter) def defaultReporter: Throwable => Unit = { - // `Error`s are currently wrapped by `resolver`. - // Also, re-throwing `Error`s here causes an exception handling test to fail. + // 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/Future.scala b/src/library/scala/concurrent/Future.scala index 70b3c3dbbb..496e4698d4 100644 --- a/src/library/scala/concurrent/Future.scala +++ b/src/library/scala/concurrent/Future.scala @@ -201,7 +201,7 @@ trait Future[+T] extends Awaitable[T] { case Right(v) => try p success f(v) catch { - case NonFatal(t) => p complete resolver(t) + case NonFatal(t) => p failure t } } @@ -227,7 +227,7 @@ trait Future[+T] extends Awaitable[T] { case Right(v) => p success v } } catch { - case NonFatal(t) => p complete resolver(t) + case NonFatal(t) => p failure t } } @@ -260,7 +260,7 @@ trait Future[+T] extends Awaitable[T] { if (pred(v)) p success v else p failure new NoSuchElementException("Future.filter predicate is not satisfied by: " + v) } catch { - case NonFatal(t) => p complete resolver(t) + case NonFatal(t) => p failure t } } @@ -309,7 +309,7 @@ trait Future[+T] extends Awaitable[T] { if (pf.isDefinedAt(v)) p success pf(v) else p failure new NoSuchElementException("Future.collect partial function is not defined at: " + v) } catch { - case NonFatal(t) => p complete resolver(t) + case NonFatal(t) => p failure t } } @@ -334,7 +334,9 @@ trait Future[+T] extends Awaitable[T] { onComplete { case Left(t) if pf isDefinedAt t => try { p success pf(t) } - catch { case NonFatal(t) => p complete resolver(t) } + catch { + case NonFatal(t) => p failure t + } case otherwise => p complete otherwise } @@ -362,7 +364,7 @@ trait Future[+T] extends Awaitable[T] { try { p completeWith pf(t) } catch { - case NonFatal(t) => p complete resolver(t) + case NonFatal(t) => p failure t } case otherwise => p complete otherwise } diff --git a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala index 7dc3ed2988..3ed960c7ab 100644 --- a/src/library/scala/concurrent/impl/ExecutionContextImpl.scala +++ b/src/library/scala/concurrent/impl/ExecutionContextImpl.scala @@ -10,10 +10,10 @@ package scala.concurrent.impl -import java.util.concurrent.{Callable, Executor, ExecutorService, Executors, ThreadFactory} +import java.util.concurrent.{ Callable, Executor, ExecutorService, Executors, ThreadFactory } import scala.concurrent.forkjoin._ -import scala.concurrent.{ExecutionContext, resolver, Awaitable} -import scala.concurrent.util.{ Duration } +import scala.concurrent.{ ExecutionContext, Awaitable } +import scala.concurrent.util.Duration diff --git a/src/library/scala/concurrent/impl/Future.scala b/src/library/scala/concurrent/impl/Future.scala index 20d4122e8f..bf136b6195 100644 --- a/src/library/scala/concurrent/impl/Future.scala +++ b/src/library/scala/concurrent/impl/Future.scala @@ -57,7 +57,7 @@ private[concurrent] object Future { case NonFatal(e) => // Commenting out reporting for now, since it produces too much output in the tests //executor.reportFailure(e) - scala.concurrent.resolver(e) + Left(e) } } }) diff --git a/src/library/scala/concurrent/impl/Promise.scala b/src/library/scala/concurrent/impl/Promise.scala index da70b3dea5..5a5b893f16 100644 --- a/src/library/scala/concurrent/impl/Promise.scala +++ b/src/library/scala/concurrent/impl/Promise.scala @@ -11,7 +11,7 @@ package scala.concurrent.impl import java.util.concurrent.TimeUnit.{ NANOSECONDS, MILLISECONDS } -import scala.concurrent.{Awaitable, ExecutionContext, resolveEither, resolver, blocking, CanAwait, TimeoutException} +import scala.concurrent.{ Awaitable, ExecutionContext, blocking, CanAwait, TimeoutException, ExecutionException } //import scala.util.continuations._ import scala.concurrent.util.Duration import scala.util @@ -26,6 +26,20 @@ private[concurrent] trait Promise[T] extends scala.concurrent.Promise[T] with Fu object Promise { + + private def resolveEither[T](source: Either[Throwable, T]): Either[Throwable, T] = source match { + case Left(t) => resolver(t) + case _ => source + } + + private def resolver[T](throwable: Throwable): Either[Throwable, T] = throwable match { + case t: scala.runtime.NonLocalReturnControl[_] => Right(t.value.asInstanceOf[T]) + case t: scala.util.control.ControlThrowable => Left(new ExecutionException("Boxed ControlThrowable", t)) + case t: InterruptedException => Left(new ExecutionException("Boxed InterruptedException", t)) + case e: Error => Left(new ExecutionException("Boxed Error", e)) + case t => Left(t) + } + /** Default promise implementation. */ class DefaultPromise[T](implicit val executor: ExecutionContext) extends AbstractPromise with Promise[T] { self => |