summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-09-22 01:16:25 -0700
committerJason Zaugg <jzaugg@gmail.com>2013-09-22 01:16:25 -0700
commit65817bd2b71f5ea0e39af1b1c2b085562cd8e925 (patch)
tree48eab984404e0389f5e50895e8bb0d79f4ea9d19
parent224e48cec22f36ff3e0e24a2f7f076062a03632a (diff)
parent9fe6b69268efc69f346e8c2d2566bbe07011bb35 (diff)
downloadscala-65817bd2b71f5ea0e39af1b1c2b085562cd8e925.tar.gz
scala-65817bd2b71f5ea0e39af1b1c2b085562cd8e925.tar.bz2
scala-65817bd2b71f5ea0e39af1b1c2b085562cd8e925.zip
Merge pull request #2949 from retronym/topic/future-from-try
Convenience methods from Try[T] => {Future, Promise}[T]
-rw-r--r--src/library/scala/concurrent/Future.scala7
-rw-r--r--src/library/scala/concurrent/Promise.scala11
2 files changed, 16 insertions, 2 deletions
diff --git a/src/library/scala/concurrent/Future.scala b/src/library/scala/concurrent/Future.scala
index ec6de84a9d..4e3f3c6c81 100644
--- a/src/library/scala/concurrent/Future.scala
+++ b/src/library/scala/concurrent/Future.scala
@@ -473,6 +473,13 @@ object Future {
*/
def successful[T](result: T): Future[T] = Promise.successful(result).future
+ /** Creates an already completed Future with the specified result or exception.
+ *
+ * @tparam T the type of the value in the promise
+ * @return the newly created `Future` object
+ */
+ def fromTry[T](result: Try[T]): Future[T] = Promise.fromTry(result).future
+
/** Starts an asynchronous computation and returns a `Future` object with the result of that computation.
*
* The result becomes available once the asynchronous computation is completed.
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)
}