From 8752eb5452ddd87ffacf96771e4367971020b213 Mon Sep 17 00:00:00 2001 From: Derek Williams Date: Tue, 3 May 2011 18:48:42 -0600 Subject: [PATCH] Add Promise factory object for creating new CompletableFutures --- akka-actor/src/main/scala/akka/dispatch/Future.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/akka-actor/src/main/scala/akka/dispatch/Future.scala b/akka-actor/src/main/scala/akka/dispatch/Future.scala index 7a0f08c6a7..9146a5282f 100644 --- a/akka-actor/src/main/scala/akka/dispatch/Future.scala +++ b/akka-actor/src/main/scala/akka/dispatch/Future.scala @@ -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). */