summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeather Miller <heather.miller@epfl.ch>2012-01-31 13:07:13 +0100
committerHeather Miller <heather.miller@epfl.ch>2012-01-31 13:07:13 +0100
commit0d23e83d136436109c957fb44ac328bdfaa8a658 (patch)
tree646bb4c4f69d933b70d5565669e5ecdd7c024b7a
parent8f36bf7a71f29af5ab61a3f58897881932c1daa3 (diff)
downloadscala-0d23e83d136436109c957fb44ac328bdfaa8a658.tar.gz
scala-0d23e83d136436109c957fb44ac328bdfaa8a658.tar.bz2
scala-0d23e83d136436109c957fb44ac328bdfaa8a658.zip
Replaced Either with Try throughout scala.concurrent.
-rw-r--r--src/library/scala/concurrent/ExecutionContext.scala11
-rw-r--r--src/library/scala/concurrent/Future.scala72
-rw-r--r--src/library/scala/concurrent/Promise.scala10
-rw-r--r--src/library/scala/concurrent/akka/ExecutionContextImpl.scala4
-rw-r--r--src/library/scala/concurrent/akka/Future.scala13
-rw-r--r--src/library/scala/concurrent/akka/Promise.scala46
-rw-r--r--src/library/scala/concurrent/default/TaskImpl.scala32
-rw-r--r--src/library/scala/concurrent/package.scala27
-rw-r--r--src/library/scala/util/Try.scala22
9 files changed, 122 insertions, 115 deletions
diff --git a/src/library/scala/concurrent/ExecutionContext.scala b/src/library/scala/concurrent/ExecutionContext.scala
index 40fafd130c..99cd264ac5 100644
--- a/src/library/scala/concurrent/ExecutionContext.scala
+++ b/src/library/scala/concurrent/ExecutionContext.scala
@@ -13,6 +13,7 @@ package scala.concurrent
import java.util.concurrent.atomic.{ AtomicInteger }
import java.util.concurrent.{ Executors, Future => JFuture, Callable }
import scala.util.Duration
+import scala.util.{ Try, Success, Failure }
import scala.concurrent.forkjoin.{ ForkJoinPool, RecursiveTask => FJTask, RecursiveAction, ForkJoinWorkerThread }
import scala.collection.generic.CanBuildFrom
import collection._
@@ -74,9 +75,9 @@ trait ExecutionContext {
buffer += null.asInstanceOf[T]
counter.incrementAndGet()
f onComplete {
- case Left(t) =>
+ case Failure(t) =>
p tryFailure t
- case Right(v) =>
+ case Success(v) =>
buffer(currentIndex) = v
tryFinish()
}
@@ -93,7 +94,7 @@ trait ExecutionContext {
*/
def any[T](futures: Traversable[Future[T]]): Future[T] = {
val p = promise[T]
- val completeFirst: Either[Throwable, T] => Unit = elem => p tryComplete elem
+ val completeFirst: Try[T] => Unit = elem => p tryComplete elem
futures foreach (_ onComplete completeFirst)
@@ -108,9 +109,9 @@ trait ExecutionContext {
else {
val result = promise[Option[T]]
val count = new AtomicInteger(futures.size)
- val search: Either[Throwable, T] => Unit = {
+ val search: Try[T] => Unit = {
v => v match {
- case Right(r) => if (predicate(r)) result trySuccess Some(r)
+ case Success(r) => if (predicate(r)) result trySuccess Some(r)
case _ =>
}
if (count.decrementAndGet() == 0) result trySuccess None
diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala
index 8d69586fbc..c87c51c0df 100644
--- a/src/library/scala/concurrent/Future.scala
+++ b/src/library/scala/concurrent/Future.scala
@@ -17,7 +17,7 @@ import java.util.{ LinkedList => JLinkedList }
import java.{ lang => jl }
import java.util.concurrent.atomic.{ AtomicReferenceFieldUpdater, AtomicInteger, AtomicBoolean }
-import scala.util.{ Timeout, Duration }
+import scala.util.{ Timeout, Duration, Try, Success, Failure }
import scala.Option
import scala.annotation.tailrec
@@ -96,8 +96,8 @@ self =>
* $multipleCallbacks
*/
def onSuccess[U](pf: PartialFunction[T, U]): this.type = onComplete {
- case Left(t) => // do nothing
- case Right(v) if pf isDefinedAt v => pf(v)
+ case Failure(t) => // do nothing
+ case Success(v) => if (pf isDefinedAt v) pf(v) else { /*do nothing*/ }
}
/** When this future is completed with a failure (i.e. with a throwable),
@@ -113,8 +113,8 @@ self =>
* $multipleCallbacks
*/
def onFailure[U](callback: PartialFunction[Throwable, U]): this.type = onComplete {
- case Left(t) if isFutureThrowable(t) => if (callback.isDefinedAt(t)) callback(t)
- case Right(v) => // do nothing
+ case Failure(t) => if (isFutureThrowable(t) && callback.isDefinedAt(t)) callback(t) else { /*do nothing*/ }
+ case Success(v) => // do nothing
}
/** When this future is completed, either through an exception, a timeout, or a value,
@@ -125,7 +125,7 @@ self =>
*
* $multipleCallbacks
*/
- def onComplete[U](func: Either[Throwable, T] => U): this.type
+ def onComplete[U](func: Try[T] => U): this.type
/* Miscellaneous */
@@ -156,8 +156,8 @@ self =>
val p = newPromise[Throwable]
onComplete {
- case Left(t) => p success t
- case Right(v) => p failure noSuchElem(v)
+ case Failure(t) => p success t
+ case Success(v) => p failure noSuchElem(v)
}
p.future
@@ -171,8 +171,8 @@ self =>
* Will not be called if the future fails.
*/
def foreach[U](f: T => U): Unit = onComplete {
- case Right(r) => f(r)
- case Left(_) => // do nothing
+ case Success(r) => f(r)
+ case Failure(_) => // do nothing
}
/** Creates a new future by applying a function to the successful result of
@@ -185,8 +185,8 @@ self =>
val p = newPromise[S]
onComplete {
- case Left(t) => p failure t
- case Right(v) =>
+ case Failure(t) => p failure t
+ case Success(v) =>
try p success f(v)
catch {
case t => p complete resolver(t)
@@ -207,12 +207,12 @@ self =>
val p = newPromise[S]
onComplete {
- case Left(t) => p failure t
- case Right(v) =>
+ case Failure(t) => p failure t
+ case Success(v) =>
try {
f(v) onComplete {
- case Left(t) => p failure t
- case Right(v) => p success v
+ case Failure(t) => p failure t
+ case Success(v) => p success v
}
} catch {
case t: Throwable => p complete resolver(t)
@@ -242,8 +242,8 @@ self =>
val p = newPromise[T]
onComplete {
- case Left(t) => p failure t
- case Right(v) =>
+ case Failure(t) => p failure t
+ case Success(v) =>
try {
if (pred(v)) p success v
else p failure new NoSuchElementException("Future.filter predicate is not satisfied by: " + v)
@@ -279,8 +279,8 @@ self =>
val p = newPromise[S]
onComplete {
- case Left(t) => p failure t
- case Right(v) =>
+ case Failure(t) => p failure t
+ case Success(v) =>
try {
if (pf.isDefinedAt(v)) p success pf(v)
else p failure new NoSuchElementException("Future.collect partial function is not defined at: " + v)
@@ -308,7 +308,7 @@ self =>
val p = newPromise[U]
onComplete {
- case Left(t) if pf isDefinedAt t =>
+ case Failure(t) if pf isDefinedAt t =>
try { p success pf(t) }
catch { case t: Throwable => p complete resolver(t) }
case otherwise => p complete otherwise
@@ -334,11 +334,11 @@ self =>
val p = newPromise[U]
onComplete {
- case Left(t) if pf isDefinedAt t =>
+ case Failure(t) if pf isDefinedAt t =>
try {
pf(t) onComplete {
- case Left(t) => p failure t
- case Right(v) => p success v
+ case Failure(t) => p failure t
+ case Success(v) => p success v
}
} catch {
case t: Throwable => p complete resolver(t)
@@ -361,8 +361,8 @@ self =>
val p = newPromise[(T, U)]
this onComplete {
- case Left(t) => p failure t
- case Right(r) => that onSuccess {
+ case Failure(t) => p failure t
+ case Success(r) => that onSuccess {
case r2 => p success ((r, r2))
}
}
@@ -392,11 +392,11 @@ self =>
val p = newPromise[U]
onComplete {
- case Left(t) => that onComplete {
- case Left(_) => p failure t
- case Right(v) => p success v
+ case Failure(t) => that onComplete {
+ case Failure(_) => p failure t
+ case Success(v) => p success v
}
- case Right(v) => p success v
+ case Success(v) => p success v
}
p.future
@@ -420,12 +420,12 @@ self =>
* f andThen {
* case r => sys.error("runtime exception")
* } andThen {
- * case Left(t) => println(t)
- * case Right(v) => println(v)
+ * case Failure(t) => println(t)
+ * case Success(v) => println(v)
* }
* }}}
*/
- def andThen[U](pf: PartialFunction[Either[Throwable, T], U]): Future[T] = {
+ def andThen[U](pf: PartialFunction[Try[T], U]): Future[T] = {
val p = newPromise[T]
onComplete {
@@ -453,9 +453,9 @@ self =>
def either[U >: T](that: Future[U]): Future[U] = {
val p = self.newPromise[U]
- val completePromise: PartialFunction[Either[Throwable, U], _] = {
- case Left(t) => p tryFailure t
- case Right(v) => p trySuccess v
+ val completePromise: PartialFunction[Try[U], _] = {
+ case Failure(t) => p tryFailure t
+ case Success(v) => p trySuccess v
}
self onComplete completePromise
diff --git a/src/library/scala/concurrent/Promise.scala b/src/library/scala/concurrent/Promise.scala
index acc02fba5f..f26deb77ab 100644
--- a/src/library/scala/concurrent/Promise.scala
+++ b/src/library/scala/concurrent/Promise.scala
@@ -8,7 +8,7 @@
package scala.concurrent
-
+import scala.util.{ Try, Success, Failure }
@@ -42,7 +42,7 @@ trait Promise[T] {
*
* $promiseCompletion
*/
- def complete(result: Either[Throwable, T]): this.type = if (tryComplete(result)) this else throwCompleted
+ def complete(result:Try[T]): this.type = if (tryComplete(result)) this else throwCompleted
/** Tries to complete the promise with either a value or the exception.
*
@@ -50,7 +50,7 @@ trait Promise[T] {
*
* @return If the promise has already been completed returns `false`, or `true` otherwise.
*/
- def tryComplete(result: Either[Throwable, T]): Boolean
+ def tryComplete(result: Try[T]): Boolean
/** Completes this promise with the specified future, once that future is completed.
*
@@ -77,7 +77,7 @@ trait Promise[T] {
*
* @return If the promise has already been completed returns `false`, or `true` otherwise.
*/
- def trySuccess(value: T): Boolean = tryComplete(Right(value))
+ def trySuccess(value: T): Boolean = tryComplete(Success(value))
/** Completes the promise with an exception.
*
@@ -95,7 +95,7 @@ trait Promise[T] {
*
* @return If the promise has already been completed returns `false`, or `true` otherwise.
*/
- def tryFailure(t: Throwable): Boolean = tryComplete(Left(t))
+ def tryFailure(t: Throwable): Boolean = tryComplete(Failure(t))
/** Wraps a `Throwable` in an `ExecutionException` if necessary. TODO replace with `resolver` from scala.concurrent
*
diff --git a/src/library/scala/concurrent/akka/ExecutionContextImpl.scala b/src/library/scala/concurrent/akka/ExecutionContextImpl.scala
index e2773e1fd5..f8c99d857b 100644
--- a/src/library/scala/concurrent/akka/ExecutionContextImpl.scala
+++ b/src/library/scala/concurrent/akka/ExecutionContextImpl.scala
@@ -12,7 +12,7 @@ package scala.concurrent.akka
import java.util.concurrent.{Callable, ExecutorService}
import scala.concurrent.{ExecutionContext, resolver, Awaitable, body2awaitable}
-import scala.util.Duration
+import scala.util.{ Duration, Try, Success, Failure }
import scala.collection.mutable.Stack
@@ -41,7 +41,7 @@ class ExecutionContextImpl(executorService: ExecutorService) extends ExecutionCo
() =>
p complete {
try {
- Right(body)
+ Success(body)
} catch {
case e => resolver(e)
}
diff --git a/src/library/scala/concurrent/akka/Future.scala b/src/library/scala/concurrent/akka/Future.scala
index be1a9ec2ae..2633e751bd 100644
--- a/src/library/scala/concurrent/akka/Future.scala
+++ b/src/library/scala/concurrent/akka/Future.scala
@@ -11,6 +11,7 @@ package scala.concurrent.akka
import scala.concurrent.{Awaitable, ExecutionContext}
+import scala.util.{ Try, Success, Failure }
//import scala.util.continuations._
@@ -35,9 +36,9 @@ trait Future[+T] extends scala.concurrent.Future[T] with Awaitable[T] {
* if it contains a valid result, or Some(Left(error)) if it contains
* an exception.
*/
- def value: Option[Either[Throwable, T]]
+ def value: Option[Try[T]]
- def onComplete[U](func: Either[Throwable, T] => U): this.type
+ def onComplete[U](func: Try[T] => U): this.type
/** Creates a new Future[A] which is completed with this Future's result if
* that conforms to A's erased type or a ClassCastException otherwise.
@@ -46,12 +47,12 @@ trait Future[+T] extends scala.concurrent.Future[T] with Awaitable[T] {
val p = executor.promise[T]
onComplete {
- case l @ Left(t) => p complete l.asInstanceOf[Either[Throwable, T]]
- case Right(v) =>
+ case f @ Failure(t) => p complete f.asInstanceOf[Try[T]]
+ case Success(v) =>
p complete (try {
- Right(boxedType(m.erasure).cast(v).asInstanceOf[T])
+ Success(boxedType(m.erasure).cast(v).asInstanceOf[T])
} catch {
- case e: ClassCastException ⇒ Left(e)
+ case e: ClassCastException ⇒ Failure(e)
})
}
diff --git a/src/library/scala/concurrent/akka/Promise.scala b/src/library/scala/concurrent/akka/Promise.scala
index fad78478a5..8ecffec2aa 100644
--- a/src/library/scala/concurrent/akka/Promise.scala
+++ b/src/library/scala/concurrent/akka/Promise.scala
@@ -15,8 +15,10 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
import scala.concurrent.{Awaitable, ExecutionContext, resolve, resolver, blocking, CanAwait, TimeoutException}
//import scala.util.continuations._
import scala.util.Duration
+import scala.util.Try
+import scala.util
import scala.annotation.tailrec
-import scala.concurrent.NonDeterministic
+//import scala.concurrent.NonDeterministic
trait Promise[T] extends scala.concurrent.Promise[T] with Future[T] {
@@ -77,18 +79,18 @@ object Promise {
/** Represents the internal state.
*/
- sealed trait FState[+T] { def value: Option[Either[Throwable, T]] }
+ sealed trait FState[+T] { def value: Option[Try[T]] }
- case class Pending[T](listeners: List[Either[Throwable, T] => Any] = Nil) extends FState[T] {
- def value: Option[Either[Throwable, T]] = None
+ case class Pending[T](listeners: List[Try[T] => Any] = Nil) extends FState[T] {
+ def value: Option[Try[T]] = None
}
- case class Success[T](value: Option[Either[Throwable, T]] = None) extends FState[T] {
- def result: T = value.get.right.get
+ case class Success[T](value: Option[util.Success[T]] = None) extends FState[T] {
+ def result: T = value.get.get
}
- case class Failure[T](value: Option[Either[Throwable, T]] = None) extends FState[T] {
- def exception: Throwable = value.get.left.get
+ case class Failure[T](value: Option[util.Failure[T]] = None) extends FState[T] {
+ def exception: Throwable = value.get.exception
}
private val emptyPendingValue = Pending[Nothing](Nil)
@@ -129,11 +131,11 @@ object Promise {
def await(atMost: Duration)(implicit permit: CanAwait): T =
ready(atMost).value.get match {
- case Left(e) => throw e
- case Right(r) => r
+ case util.Failure(e) => throw e
+ case util.Success(r) => r
}
- def value: Option[Either[Throwable, T]] = getState.value
+ def value: Option[Try[T]] = getState.value
@inline
private[this] final def updater = AbstractPromise.updater.asInstanceOf[AtomicReferenceFieldUpdater[AbstractPromise, FState[T]]]
@@ -144,14 +146,14 @@ object Promise {
@inline
protected final def getState: FState[T] = updater.get(this)
- def tryComplete(value: Either[Throwable, T]): Boolean = {
- val callbacks: List[Either[Throwable, T] => Any] = {
+ def tryComplete(value: Try[T]): Boolean = {
+ val callbacks: List[Try[T] => Any] = {
try {
@tailrec
- def tryComplete(v: Either[Throwable, T]): List[Either[Throwable, T] => Any] = {
+ def tryComplete(v: Try[T]): List[Try[T] => Any] = {
getState match {
case cur @ Pending(listeners) =>
- if (updateState(cur, if (v.isLeft) Failure(Some(v)) else Success(Some(v)))) listeners
+ if (updateState(cur, if (v.isFailure) Failure(Some(v.asInstanceOf[util.Failure[T]])) else Success(Some(v.asInstanceOf[util.Success[T]])))) listeners
else tryComplete(v)
case _ => null
}
@@ -173,7 +175,7 @@ object Promise {
}
}
- def onComplete[U](func: Either[Throwable, T] => U): this.type = {
+ def onComplete[U](func: Try[T] => U): this.type = {
@tailrec // Returns whether the future has already been completed or not
def tryAddCallback(): Boolean = {
val cur = getState
@@ -195,7 +197,7 @@ object Promise {
this
}
- private final def notifyCompleted(func: Either[Throwable, T] => Any, result: Either[Throwable, T]) {
+ private final def notifyCompleted(func: Try[T] => Any, result: Try[T]) {
try {
func(result)
} catch {
@@ -208,12 +210,12 @@ object Promise {
*
* Useful in Future-composition when a value to contribute is already available.
*/
- final class KeptPromise[T](suppliedValue: Either[Throwable, T])(implicit val executor: ExecutionContextImpl) extends Promise[T] {
+ final class KeptPromise[T](suppliedValue: Try[T])(implicit val executor: ExecutionContextImpl) extends Promise[T] {
val value = Some(resolve(suppliedValue))
- def tryComplete(value: Either[Throwable, T]): Boolean = false
+ def tryComplete(value: Try[T]): Boolean = false
- def onComplete[U](func: Either[Throwable, T] => U): this.type = {
+ def onComplete[U](func: Try[T] => U): this.type = {
val completedAs = value.get
executor dispatchFuture {
() => func(completedAs)
@@ -224,8 +226,8 @@ object Promise {
private def ready(atMost: Duration)(implicit permit: CanAwait): this.type = this
def await(atMost: Duration)(implicit permit: CanAwait): T = value.get match {
- case Left(e) => throw e
- case Right(r) => r
+ case util.Failure(e) => throw e
+ case util.Success(r) => r
}
}
diff --git a/src/library/scala/concurrent/default/TaskImpl.scala b/src/library/scala/concurrent/default/TaskImpl.scala
index 7ac297de9e..94e54cb372 100644
--- a/src/library/scala/concurrent/default/TaskImpl.scala
+++ b/src/library/scala/concurrent/default/TaskImpl.scala
@@ -5,6 +5,8 @@ package default
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater
import scala.concurrent.forkjoin.{ ForkJoinPool, RecursiveAction, ForkJoinWorkerThread }
+import scala.util.Try
+import scala.util
import scala.util.Duration
import scala.annotation.tailrec
@@ -17,7 +19,7 @@ self: Future[T] =>
def newPromise[S]: Promise[S] = executor promise
- type Callback = Either[Throwable, T] => Any
+ type Callback = Try[T] => Any
def getState: State[T]
@@ -25,22 +27,22 @@ self: Future[T] =>
protected def dispatch[U](r: Runnable) = executionContext execute r
- protected def processCallbacks(cbs: List[Callback], r: Either[Throwable, T]) =
+ protected def processCallbacks(cbs: List[Callback], r: Try[T]) =
for (cb <- cbs) dispatch(new Runnable {
override def run() = cb(r)
})
def future: Future[T] = self
- def onComplete[U](callback: Either[Throwable, T] => U): this.type = {
- @tailrec def tryAddCallback(): Either[Throwable, T] = {
+ def onComplete[U](callback: Try[T] => U): this.type = {
+ @tailrec def tryAddCallback(): Try[T] = {
getState match {
case p @ Pending(lst) =>
val pt = p.asInstanceOf[Pending[T]]
if (casState(pt, Pending(callback :: pt.callbacks))) null
else tryAddCallback()
- case Success(res) => Right(res)
- case Failure(t) => Left(t)
+ case Success(res) => util.Success(res)
+ case Failure(t) => util.Failure(t)
}
}
@@ -87,9 +89,9 @@ extends Promise[T] with Future[T] with Completable[T] {
case _ => null
}
- def tryComplete(r: Either[Throwable, T]) = r match {
- case Left(t) => tryFailure(t)
- case Right(v) => trySuccess(v)
+ def tryComplete(r: Try[T]) = r match {
+ case util.Failure(t) => tryFailure(t)
+ case util.Success(v) => trySuccess(v)
}
override def trySuccess(value: T): Boolean = {
@@ -97,7 +99,7 @@ extends Promise[T] with Future[T] with Completable[T] {
if (cbs == null)
false
else {
- processCallbacks(cbs, Right(value))
+ processCallbacks(cbs, util.Success(value))
this.synchronized {
this.notifyAll()
}
@@ -111,7 +113,7 @@ extends Promise[T] with Future[T] with Completable[T] {
if (cbs == null)
false
else {
- processCallbacks(cbs, Left(wrapped))
+ processCallbacks(cbs, util.Failure(wrapped))
this.synchronized {
this.notifyAll()
}
@@ -163,13 +165,13 @@ extends RecursiveAction with Task[T] with Future[T] with Completable[T] {
var cbs: List[Callback] = null
try {
val res = body
- processCallbacks(tryCompleteState(Success(res)), Right(res))
+ processCallbacks(tryCompleteState(Success(res)), util.Success(res))
} catch {
case t if isFutureThrowable(t) =>
- processCallbacks(tryCompleteState(Failure(t)), Left(t))
+ processCallbacks(tryCompleteState(Failure(t)), util.Failure(t))
case t =>
val ee = new ExecutionException(t)
- processCallbacks(tryCompleteState(Failure(ee)), Left(ee))
+ processCallbacks(tryCompleteState(Failure(ee)), util.Failure(ee))
throw t
}
}
@@ -207,7 +209,7 @@ extends RecursiveAction with Task[T] with Future[T] with Completable[T] {
private[concurrent] sealed abstract class State[T]
-case class Pending[T](callbacks: List[Either[Throwable, T] => Any]) extends State[T]
+case class Pending[T](callbacks: List[Try[T] => Any]) extends State[T]
case class Success[T](result: T) extends State[T]
diff --git a/src/library/scala/concurrent/package.scala b/src/library/scala/concurrent/package.scala
index 5c3f1f818d..35b8cf6664 100644
--- a/src/library/scala/concurrent/package.scala
+++ b/src/library/scala/concurrent/package.scala
@@ -10,7 +10,7 @@ package scala
-import scala.util.Duration
+import scala.util.{ Duration, Try, Success, Failure }
@@ -44,23 +44,24 @@ package object concurrent {
case _ => true
}
- private[concurrent] def resolve[T](source: Either[Throwable, T]): Either[Throwable, T] = source match {
- case Left(t: scala.runtime.NonLocalReturnControl[_]) => Right(t.value.asInstanceOf[T])
- case Left(t: scala.util.control.ControlThrowable) => Left(new ExecutionException("Boxed ControlThrowable", t))
- case Left(t: InterruptedException) => Left(new ExecutionException("Boxed InterruptedException", t))
- case Left(e: Error) => Left(new ExecutionException("Boxed Error", e))
+ private[concurrent] def resolve[T](source: Try[T]): Try[T] = source match {
+ case Failure(t: scala.runtime.NonLocalReturnControl[_]) => Success(t.value.asInstanceOf[T])
+ case Failure(t: scala.util.control.ControlThrowable) => Failure(new ExecutionException("Boxed ControlThrowable", t))
+ case Failure(t: InterruptedException) => Failure(new ExecutionException("Boxed InterruptedException", t))
+ case Failure(e: Error) => Failure(new ExecutionException("Boxed Error", e))
case _ => source
}
- 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)
+ // TODO, docs, return type
+ private val resolverFunction: PartialFunction[Throwable, Try[_]] = {
+ case t: scala.runtime.NonLocalReturnControl[_] => Success(t.value)
+ case t: scala.util.control.ControlThrowable => Failure(new ExecutionException("Boxed ControlThrowable", t))
+ case t: InterruptedException => Failure(new ExecutionException("Boxed InterruptedException", t))
+ case e: Error => Failure(new ExecutionException("Boxed Error", e))
+ case t => Failure(t)
}
- private[concurrent] def resolver[T] = resolverFunction.asInstanceOf[PartialFunction[Throwable, Either[Throwable, T]]]
+ private[concurrent] def resolver[T] = resolverFunction.asInstanceOf[PartialFunction[Throwable, Try[T]]]
/* concurrency constructs */
diff --git a/src/library/scala/util/Try.scala b/src/library/scala/util/Try.scala
index b82570cd05..a05a75e0b7 100644
--- a/src/library/scala/util/Try.scala
+++ b/src/library/scala/util/Try.scala
@@ -66,7 +66,7 @@ sealed abstract class Try[+T] {
/**
* Converts this to a `Failure` if the predicate is not satisfied.
*/
- def filterNote(p: T => Boolean): Try[T] = filter(x => !p(x))
+ def filterNot(p: T => Boolean): Try[T] = filter(x => !p(x))
/**
* Calls the exceptionHandler with the exception if this is a `Failure`. This is like `flatMap` for the exception.
@@ -101,31 +101,31 @@ sealed abstract class Try[+T] {
}
-final case class Failure[+T](e: Throwable) extends Try[T] {
+final case class Failure[+T](val exception: Throwable) extends Try[T] {
def isFailure = true
def isSuccess = false
def rescue[U >: T](rescueException: PartialFunction[Throwable, Try[U]]): Try[U] = {
try {
- if (rescueException.isDefinedAt(e)) rescueException(e) else this
+ if (rescueException.isDefinedAt(exception)) rescueException(exception) else this
} catch {
case e2 => Failure(e2)
}
}
- def get: T = throw e
- def flatMap[U](f: T => Try[U]): Try[U] = Failure[U](e)
- def flatten[U](implicit ev: T <:< Try[U]): Try[U] = Failure[U](e)
+ def get: T = throw exception
+ def flatMap[U](f: T => Try[U]): Try[U] = Failure[U](exception)
+ def flatten[U](implicit ev: T <:< Try[U]): Try[U] = Failure[U](exception)
def foreach[U](f: T => U): Unit = {}
- def map[U](f: T => U): Try[U] = Failure[U](e)
- def collect[U](pf: PartialFunction[T, U]): Try[U] = Failure[U](e)
+ def map[U](f: T => U): Try[U] = Failure[U](exception)
+ def collect[U](pf: PartialFunction[T, U]): Try[U] = Failure[U](exception)
def filter(p: T => Boolean): Try[T] = this
def recover[U >: T](rescueException: PartialFunction[Throwable, U]): Try[U] =
- if (rescueException.isDefinedAt(e)) {
- Try(rescueException(e))
+ if (rescueException.isDefinedAt(exception)) {
+ Try(rescueException(exception))
} else {
this
}
def exists(p: T => Boolean): Boolean = false
- def failed: Try[Throwable] = Success(e)
+ def failed: Try[Throwable] = Success(exception)
}