Add Promise factory object for creating new CompletableFutures

This commit is contained in:
Derek Williams 2011-05-03 18:48:42 -06:00
parent 5b18f18ffd
commit 8752eb5452

View file

@ -292,7 +292,7 @@ object Future {
* The Delimited Continuations compiler plugin must be enabled in order to use this method.
*/
def flow[A](body: => A @cps[Future[Any]], timeout: Long = Actor.TIMEOUT): Future[A] = {
val future = new DefaultCompletableFuture[A](timeout)
val future = Promise[A](timeout)
(reset(future.asInstanceOf[CompletableFuture[Any]].completeWithResult(body)): Future[Any]) onComplete { f =>
val opte = f.exception
if (opte.isDefined) future completeWithException (opte.get)
@ -613,6 +613,14 @@ sealed trait Future[+T] {
}
object Promise {
def apply[A](timeout: Long): CompletableFuture[A] = new DefaultCompletableFuture[A](timeout)
def apply[A](): CompletableFuture[A] = apply(Actor.TIMEOUT)
}
/**
* Essentially this is the Promise (or write-side) of a Future (read-side).
*/