diff options
author | Heather Miller <heather.miller@epfl.ch> | 2012-08-07 18:36:36 +0200 |
---|---|---|
committer | Heather Miller <heather.miller@epfl.ch> | 2012-08-07 18:36:36 +0200 |
commit | ea81ab3314359c98986e6fac74c807fa1accdfb6 (patch) | |
tree | d39d7d549e765af105e1c0808808a8ea5d340037 /src | |
parent | 505cc713ec4546c5f9be1065e5fa3f7065451b8f (diff) | |
download | scala-ea81ab3314359c98986e6fac74c807fa1accdfb6.tar.gz scala-ea81ab3314359c98986e6fac74c807fa1accdfb6.tar.bz2 scala-ea81ab3314359c98986e6fac74c807fa1accdfb6.zip |
Added tests, removal of unnecessary methods, fixes prepare
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/concurrent/ExecutionContext.scala | 8 | ||||
-rw-r--r-- | src/library/scala/concurrent/impl/Promise.scala | 9 | ||||
-rw-r--r-- | src/library/scala/util/Try.scala | 13 |
3 files changed, 7 insertions, 23 deletions
diff --git a/src/library/scala/concurrent/ExecutionContext.scala b/src/library/scala/concurrent/ExecutionContext.scala index ac462ac9d2..82c1cff4b1 100644 --- a/src/library/scala/concurrent/ExecutionContext.scala +++ b/src/library/scala/concurrent/ExecutionContext.scala @@ -28,12 +28,10 @@ trait ExecutionContext { */ def reportFailure(t: Throwable): Unit - /** Prepares for the execution of callback `f`. Returns the prepared - * execution context which should be used to schedule the execution - * of the task associated with `f`. + /** Prepares for the execution of a task. Returns the prepared + * execution context. */ - def prepare[T, U](f: Try[T] => U): ExecutionContext = - this + def prepare(): ExecutionContext = this } diff --git a/src/library/scala/concurrent/impl/Promise.scala b/src/library/scala/concurrent/impl/Promise.scala index 9f30529dc8..b19bed004b 100644 --- a/src/library/scala/concurrent/impl/Promise.scala +++ b/src/library/scala/concurrent/impl/Promise.scala @@ -129,7 +129,7 @@ private[concurrent] object Promise { } def onComplete[U](func: Try[T] => U)(implicit executor: ExecutionContext): Unit = { - val preparedEC = executor.prepare(func) + val preparedEC = executor.prepare val runnable = new CallbackRunnable[T](preparedEC, func) @tailrec //Tries to add the callback, if already completed, it dispatches the callback to be executed @@ -156,16 +156,13 @@ private[concurrent] object Promise { def onComplete[U](func: Try[T] => U)(implicit executor: ExecutionContext): Unit = { val completedAs = value.get - val preparedEC = executor.prepare(func) + val preparedEC = executor.prepare (new CallbackRunnable(preparedEC, func)).executeWithValue(completedAs) } def ready(atMost: Duration)(implicit permit: CanAwait): this.type = this - def result(atMost: Duration)(implicit permit: CanAwait): T = value.get match { - case Failure(e) => throw e - case Success(r) => r - } + def result(atMost: Duration)(implicit permit: CanAwait): T = value.get.get } } diff --git a/src/library/scala/util/Try.scala b/src/library/scala/util/Try.scala index c834f6d514..f381a18b0c 100644 --- a/src/library/scala/util/Try.scala +++ b/src/library/scala/util/Try.scala @@ -54,7 +54,7 @@ import language.implicitConversions * * `Try` comes to the Scala standard library after years of use as an integral part of Twitter's stack. * - * @author based on Marius Eriksen's original implementation in com.twitter.util. + * @author based on Twitter's original implementation in com.twitter.util. * @since 2.10 */ sealed abstract class Try[+T] { @@ -117,17 +117,6 @@ sealed abstract class Try[+T] { def toOption = if (isSuccess) Some(get) else None /** - * Returns an empty `Seq` (usually a `List`) if this is a `Failure` or a `Seq` containing the value if this is a `Success`. - */ - def toSeq = if (isSuccess) Seq(get) else Seq() - - /** - * Returns the given function applied to the value from this `Success` or returns this if this is a `Failure`. - * Alias for `flatMap`. - */ - def andThen[U](f: T => Try[U]): Try[U] = flatMap(f) - - /** * Transforms a nested `Try`, ie, a `Try` of type `Try[Try[T]]`, * into an un-nested `Try`, ie, a `Try` of type `Try[T]`. */ |