diff options
author | Philipp Haller <hallerp@gmail.com> | 2010-04-29 09:44:30 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2010-04-29 09:44:30 +0000 |
commit | d6178b3a1037fcad01e98f4e5cc9e77a51dbabbd (patch) | |
tree | 82aaaa522c0be3c11145dc5a58903abcb9eb4642 | |
parent | ee5daee5d82c76d441341c8ffa81d72839e4e726 (diff) | |
download | scala-d6178b3a1037fcad01e98f4e5cc9e77a51dbabbd.tar.gz scala-d6178b3a1037fcad01e98f4e5cc9e77a51dbabbd.tar.bz2 scala-d6178b3a1037fcad01e98f4e5cc9e77a51dbabbd.zip |
Made internal helper methods in concurrent.ops ...
Made internal helper methods in concurrent.ops private. Removed
protected tryCatch helper method from concurrent.TaskRunner. Review by
rompf.
-rw-r--r-- | src/library/scala/concurrent/TaskRunner.scala | 5 | ||||
-rw-r--r-- | src/library/scala/concurrent/ThreadRunner.scala | 10 | ||||
-rw-r--r-- | src/library/scala/concurrent/ops.scala | 16 |
3 files changed, 13 insertions, 18 deletions
diff --git a/src/library/scala/concurrent/TaskRunner.scala b/src/library/scala/concurrent/TaskRunner.scala index 0853007a28..f7d3002b83 100644 --- a/src/library/scala/concurrent/TaskRunner.scala +++ b/src/library/scala/concurrent/TaskRunner.scala @@ -25,9 +25,4 @@ trait TaskRunner { def shutdown(): Unit - /** If expression computed successfully return it in <code>Right</code>, - * otherwise return exception in <code>Left</code>. - */ - protected def tryCatch[A](body: => A): Either[Exception, A] = - ops tryCatchEx body } diff --git a/src/library/scala/concurrent/ThreadRunner.scala b/src/library/scala/concurrent/ThreadRunner.scala index 13bf20ff2a..5cfc076699 100644 --- a/src/library/scala/concurrent/ThreadRunner.scala +++ b/src/library/scala/concurrent/ThreadRunner.scala @@ -25,6 +25,14 @@ class ThreadRunner extends FutureTaskRunner { implicit def functionAsTask[S](fun: () => S): Task[S] = fun implicit def futureAsFunction[S](x: Future[S]): () => S = x + /* If expression computed successfully return it in `Right`, + * otherwise return exception in `Left`. + */ + private def tryCatch[A](body: => A): Either[Exception, A] = + try Right(body) catch { + case ex: Exception => Left(ex) + } + def execute[S](task: Task[S]) { val runnable = new Runnable { def run() { tryCatch(task()) } @@ -38,7 +46,7 @@ class ThreadRunner extends FutureTaskRunner { def run() { result set tryCatch(task()) } } (new Thread(runnable)).start() - () => ops getOrThrow result.get + () => result.get.fold[S](throw _, identity _) } def managedBlock(blocker: ManagedBlocker) { diff --git a/src/library/scala/concurrent/ops.scala b/src/library/scala/concurrent/ops.scala index 6537a47258..49be1b882c 100644 --- a/src/library/scala/concurrent/ops.scala +++ b/src/library/scala/concurrent/ops.scala @@ -23,21 +23,13 @@ object ops val defaultRunner: FutureTaskRunner = TaskRunners.threadRunner /** - * If expression computed successfully return it in <code>Right</code>, - * otherwise return exception in <code>Left</code>. + * If expression computed successfully return it in `Right`, + * otherwise return exception in `Left`. */ - //TODO: make private - def tryCatch[A](body: => A): Either[Throwable, A] = + private def tryCatch[A](body: => A): Either[Throwable, A] = allCatch[A] either body - //TODO: make private - def tryCatchEx[A](body: => A): Either[Exception, A] = - try Right(body) catch { - case ex: Exception => Left(ex) - } - - //TODO: make private - def getOrThrow[T <: Throwable, A](x: Either[T, A]): A = + private def getOrThrow[T <: Throwable, A](x: Either[T, A]): A = x.fold[A](throw _, identity _) /** Evaluates an expression asynchronously. |