From 4bd00bc92ff3de95d41b0d8acc9c826426cf9589 Mon Sep 17 00:00:00 2001 From: Derek Williams Date: Mon, 28 Feb 2011 11:47:39 -0700 Subject: [PATCH] Add friendlier method of starting a Future --- akka-actor/src/main/scala/akka/dispatch/Future.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/akka-actor/src/main/scala/akka/dispatch/Future.scala b/akka-actor/src/main/scala/akka/dispatch/Future.scala index 71bb644926..5cef4de971 100644 --- a/akka-actor/src/main/scala/akka/dispatch/Future.scala +++ b/akka-actor/src/main/scala/akka/dispatch/Future.scala @@ -138,6 +138,14 @@ object Futures { }.map(_.result) } +object Future { + def apply[T](body: => T, timeout: Long = Actor.TIMEOUT)(implicit dispatcher: MessageDispatcher): Future[T] = { + val f = new DefaultCompletableFuture[T](timeout) + dispatcher.dispatchFuture(FutureInvocation(f.asInstanceOf[CompletableFuture[Any]], () => body)) + f + } +} + sealed trait Future[T] { /** * Blocks the current thread until the Future has been completed or the