diff --git a/akka-actor/src/main/scala/akka/dispatch/Future.scala b/akka-actor/src/main/scala/akka/dispatch/Future.scala index 2ec53da7ec..2d8feaafa1 100644 --- a/akka-actor/src/main/scala/akka/dispatch/Future.scala +++ b/akka-actor/src/main/scala/akka/dispatch/Future.scala @@ -5,12 +5,11 @@ package akka.dispatch import akka.AkkaException -import akka.actor.Actor.spawn import akka.routing.Dispatcher import java.util.concurrent.locks.ReentrantLock import akka.japi.Procedure -import java.util.concurrent. {ConcurrentLinkedQueue, TimeUnit} +import java.util.concurrent. {ConcurrentLinkedQueue, TimeUnit, Callable} import java.util.concurrent.TimeUnit.{NANOSECONDS => NANOS, MILLISECONDS => MILLIS} import akka.actor.Actor import annotation.tailrec @@ -20,20 +19,17 @@ class FutureTimeoutException(message: String) extends AkkaException(message) object Futures { - /** - * Module with utility methods for working with Futures. - *
-   * val future = Futures.future(1000) {
-   *  ... // do stuff
-   * }
-   * 
- */ - def future[T](body: => T, timeout: Long = Actor.TIMEOUT, - dispatcher: MessageDispatcher = Dispatchers.defaultGlobalDispatcher): Future[T] = { - val f = new DefaultCompletableFuture[T](timeout) - dispatcher.dispatchFuture(FutureInvocation(f.asInstanceOf[CompletableFuture[Any]], () => body)) - f - } + def future[T](body: Callable[T]): Future[T] = + Future(body.call) + + def future[T](body: Callable[T], timeout: Long): Future[T] = + Future(body.call, timeout) + + def future[T](body: Callable[T], dispatcher: MessageDispatcher): Future[T] = + Future(body.call)(dispatcher) + + def future[T](body: Callable[T], timeout: Long, dispatcher: MessageDispatcher): Future[T] = + Future(body.call, timeout)(dispatcher) /** * (Blocking!) diff --git a/akka-actor/src/test/scala/akka/dispatch/FutureSpec.scala b/akka-actor/src/test/scala/akka/dispatch/FutureSpec.scala index 117631ca0b..f6347b56d2 100644 --- a/akka-actor/src/test/scala/akka/dispatch/FutureSpec.scala +++ b/akka-actor/src/test/scala/akka/dispatch/FutureSpec.scala @@ -210,7 +210,7 @@ class FutureSpec extends JUnitSuite { }).start } def futures = actors.zipWithIndex map { case (actor: ActorRef, idx: Int) => actor.!!![Int]((idx, idx * 200 )) } - assert(futures.foldLeft(Futures.future(0))((fr, fa) => fr flatMap (r => fa map (_ + r))).awaitBlocking.result.get === 45) + assert(futures.foldLeft(Future(0))((fr, fa) => for (r <- fr; a <- fa) yield (r + a)).awaitBlocking.result.get === 45) } @Test def shouldFoldResultsWithException {