Permalink
Browse files

Move resolver and resolveEither to impl.Promise

  • Loading branch information...
phaller committed May 10, 2012
1 parent b0e8533 commit 3fdc05278918df210b0c2b859f4588e14051bd41
@@ -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)
// }
}
@@ -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()
}
@@ -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
}
@@ -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
@@ -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)
}
}
})
@@ -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 =>

0 comments on commit 3fdc052

Please sign in to comment.