Add Promise factory object for creating new CompletableFutures
This commit is contained in:
parent
5b18f18ffd
commit
8752eb5452
1 changed files with 9 additions and 1 deletions
|
|
@ -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).
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue