summaryrefslogtreecommitdiff
path: root/src/library/scala/concurrent/Promise.scala
diff options
context:
space:
mode:
authorHeather Miller <heather.miller@epfl.ch>2012-08-04 21:55:35 +0200
committerHeather Miller <heather.miller@epfl.ch>2012-08-04 21:55:35 +0200
commit3cb0e784a05db7d0b542cec9bf4c5fbf3772a6cf (patch)
tree36c1a6040e0f0aa6e64c0eef6fb55bea61bf4141 /src/library/scala/concurrent/Promise.scala
parentab63cca87f68d80aff0ff6cd83ecd85b9e1d0c7a (diff)
downloadscala-3cb0e784a05db7d0b542cec9bf4c5fbf3772a6cf.tar.gz
scala-3cb0e784a05db7d0b542cec9bf4c5fbf3772a6cf.tar.bz2
scala-3cb0e784a05db7d0b542cec9bf4c5fbf3772a6cf.zip
Basing Futures on Try instead of Either
Diffstat (limited to 'src/library/scala/concurrent/Promise.scala')
-rw-r--r--src/library/scala/concurrent/Promise.scala18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/library/scala/concurrent/Promise.scala b/src/library/scala/concurrent/Promise.scala
index 5d1b2c00b6..b873939c15 100644
--- a/src/library/scala/concurrent/Promise.scala
+++ b/src/library/scala/concurrent/Promise.scala
@@ -8,6 +8,8 @@
package scala.concurrent
+import scala.util.{ Try, Success, Failure }
+
/** Promise is an object which can be completed with a value or failed
* with an exception.
*
@@ -49,7 +51,7 @@ trait Promise[T] {
*
* $promiseCompletion
*/
- def complete(result: Either[Throwable, T]): this.type =
+ def complete(result: Try[T]): this.type =
if (tryComplete(result)) this else throw new IllegalStateException("Promise already completed.")
/** Tries to complete the promise with either a value or the exception.
@@ -58,7 +60,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.
*
@@ -84,7 +86,7 @@ trait Promise[T] {
*
* $promiseCompletion
*/
- def success(v: T): this.type = complete(Right(v))
+ def success(v: T): this.type = complete(Success(v))
/** Tries to complete the promise with a value.
*
@@ -92,7 +94,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.
*
@@ -102,7 +104,7 @@ trait Promise[T] {
*
* $promiseCompletion
*/
- def failure(t: Throwable): this.type = complete(Left(t))
+ def failure(t: Throwable): this.type = complete(Failure(t))
/** Tries to complete the promise with an exception.
*
@@ -110,7 +112,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))
}
@@ -129,14 +131,14 @@ object Promise {
* @tparam T the type of the value in the promise
* @return the newly created `Promise` object
*/
- def failed[T](exception: Throwable): Promise[T] = new impl.Promise.KeptPromise[T](Left(exception))
+ def failed[T](exception: Throwable): Promise[T] = new impl.Promise.KeptPromise[T](Failure(exception))
/** Creates an already completed Promise with the specified result.
*
* @tparam T the type of the value in the promise
* @return the newly created `Promise` object
*/
- def successful[T](result: T): Promise[T] = new impl.Promise.KeptPromise[T](Right(result))
+ def successful[T](result: T): Promise[T] = new impl.Promise.KeptPromise[T](Success(result))
}