summaryrefslogtreecommitdiff
path: root/src/library/scala/concurrent/Promise.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-09-16 10:32:12 +0200
committerJason Zaugg <jzaugg@gmail.com>2013-09-19 18:07:38 +0200
commit9fe6b69268efc69f346e8c2d2566bbe07011bb35 (patch)
treee704b7db614a3278ffe3c509f2623fa0b5397c9d /src/library/scala/concurrent/Promise.scala
parent884e1ce762d98b29594146d37b85384581d9ba96 (diff)
downloadscala-9fe6b69268efc69f346e8c2d2566bbe07011bb35.tar.gz
scala-9fe6b69268efc69f346e8c2d2566bbe07011bb35.tar.bz2
scala-9fe6b69268efc69f346e8c2d2566bbe07011bb35.zip
Convenience methods from Try[T] => {Future, Promise}[T]
Diffstat (limited to 'src/library/scala/concurrent/Promise.scala')
-rw-r--r--src/library/scala/concurrent/Promise.scala11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/library/scala/concurrent/Promise.scala b/src/library/scala/concurrent/Promise.scala
index cfb1dda01f..eb8044ed3b 100644
--- a/src/library/scala/concurrent/Promise.scala
+++ b/src/library/scala/concurrent/Promise.scala
@@ -128,12 +128,19 @@ 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](Failure(exception))
+ def failed[T](exception: Throwable): Promise[T] = fromTry(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](Success(result))
+ def successful[T](result: T): Promise[T] = fromTry(Success(result))
+
+ /** Creates an already completed Promise with the specified result or exception.
+ *
+ * @tparam T the type of the value in the promise
+ * @return the newly created `Promise` object
+ */
+ def fromTry[T](result: Try[T]): Promise[T] = new impl.Promise.KeptPromise[T](result)
}