summaryrefslogtreecommitdiff
path: root/src/library/scala/concurrent/Promise.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-02-29 11:13:44 -0800
committerPaul Phillips <paulp@improving.org>2012-02-29 11:13:44 -0800
commita183c6ad31011b4fb1785655dd3d671b8f5bb519 (patch)
treebbedd1f23b437d36e4796f1ca7ec40dcc96c18e1 /src/library/scala/concurrent/Promise.scala
parentfc2866efee1bcf17aee18d427ed41e172f440f62 (diff)
downloadscala-a183c6ad31011b4fb1785655dd3d671b8f5bb519.tar.gz
scala-a183c6ad31011b4fb1785655dd3d671b8f5bb519.tar.bz2
scala-a183c6ad31011b4fb1785655dd3d671b8f5bb519.zip
Whitespace commit.
Removed all the trailing whitespace to make eugene happier. Will try to keep it that way by protecting at the merge level. Left the tabs in place because they can't be uniformly changed to spaces, some are 2, some are 4, some are 8, whee.
Diffstat (limited to 'src/library/scala/concurrent/Promise.scala')
-rw-r--r--src/library/scala/concurrent/Promise.scala64
1 files changed, 32 insertions, 32 deletions
diff --git a/src/library/scala/concurrent/Promise.scala b/src/library/scala/concurrent/Promise.scala
index f26deb77ab..4404e90971 100644
--- a/src/library/scala/concurrent/Promise.scala
+++ b/src/library/scala/concurrent/Promise.scala
@@ -24,36 +24,36 @@ import scala.util.{ Try, Success, Failure }
* If the throwable used to fail this promise is an error, a control exception
* or an interrupted exception, it will be wrapped as a cause within an
* `ExecutionException` which will fail the promise.
- *
+ *
* @define nonDeterministic
* Note: Using this method may result in non-deterministic concurrent programs.
*/
trait Promise[T] {
-
+
import nondeterministic._
-
+
/** Future containing the value of this promise.
*/
def future: Future[T]
-
+
/** Completes the promise with either an exception or a value.
- *
+ *
* @param result Either the value or the exception to complete the promise with.
- *
+ *
* $promiseCompletion
*/
def complete(result:Try[T]): this.type = if (tryComplete(result)) this else throwCompleted
-
+
/** Tries to complete the promise with either a value or the exception.
- *
+ *
* $nonDeterministic
- *
+ *
* @return If the promise has already been completed returns `false`, or `true` otherwise.
*/
def tryComplete(result: Try[T]): Boolean
-
+
/** Completes this promise with the specified future, once that future is completed.
- *
+ *
* @return This promise
*/
final def completeWith(other: Future[T]): this.type = {
@@ -62,64 +62,64 @@ trait Promise[T] {
}
this
}
-
+
/** Completes the promise with a value.
- *
+ *
* @param value The value to complete the promise with.
- *
+ *
* $promiseCompletion
*/
def success(v: T): this.type = if (trySuccess(v)) this else throwCompleted
-
+
/** Tries to complete the promise with a value.
- *
+ *
* $nonDeterministic
- *
+ *
* @return If the promise has already been completed returns `false`, or `true` otherwise.
*/
def trySuccess(value: T): Boolean = tryComplete(Success(value))
-
+
/** Completes the promise with an exception.
- *
+ *
* @param t The throwable to complete the promise with.
- *
+ *
* $allowedThrowables
- *
+ *
* $promiseCompletion
*/
def failure(t: Throwable): this.type = if (tryFailure(t)) this else throwCompleted
-
+
/** Tries to complete the promise with an exception.
- *
+ *
* $nonDeterministic
- *
+ *
* @return If the promise has already been completed returns `false`, or `true` otherwise.
*/
def tryFailure(t: Throwable): Boolean = tryComplete(Failure(t))
-
+
/** Wraps a `Throwable` in an `ExecutionException` if necessary. TODO replace with `resolver` from scala.concurrent
- *
+ *
* $allowedThrowables
*/
protected def wrap(t: Throwable): Throwable = t match {
case t: Throwable if isFutureThrowable(t) => t
case _ => new ExecutionException(t)
}
-
+
private def throwCompleted = throw new IllegalStateException("Promise already completed.")
-
+
}
object Promise {
-
+
def kept[T](result: T)(implicit execctx: ExecutionContext): Promise[T] =
execctx keptPromise result
-
- def broken[T](t: Throwable)(implicit execctx: ExecutionContext): Promise[T] =
+
+ def broken[T](t: Throwable)(implicit execctx: ExecutionContext): Promise[T] =
execctx brokenPromise t
-
+
}