diff --git a/akka-actor/src/main/scala/dispatch/Future.scala b/akka-actor/src/main/scala/dispatch/Future.scala index c0b20b2053..3fd1c708e4 100644 --- a/akka-actor/src/main/scala/dispatch/Future.scala +++ b/akka-actor/src/main/scala/dispatch/Future.scala @@ -5,9 +5,10 @@ package se.scalablesolutions.akka.dispatch import se.scalablesolutions.akka.AkkaException - +import se.scalablesolutions.akka.actor.Actor.spawn import java.util.concurrent.locks.ReentrantLock import java.util.concurrent.TimeUnit +import se.scalablesolutions.akka.routing.Dispatcher class FutureTimeoutException(message: String) extends AkkaException(message) @@ -20,18 +21,19 @@ object Futures { * ... // do stuff * } * - * - def future[T](timeout: Long)(body: => T): Future[T] = { - val promise = new DefaultCompletableFuture[T](timeout) + */ + def future[T](timeout: Long, + dispatcher: MessageDispatcher = Dispatchers.defaultGlobalDispatcher) + (body: => T): Future[T] = { + val f = new DefaultCompletableFuture[T](timeout) - try { - promise completeWithResult body - } catch { - case e => promise completeWithException e - } - promise + spawn({ + try { f completeWithResult body } + catch { case e => f completeWithException e} + })(dispatcher) + + f } - */ def awaitAll(futures: List[Future[_]]): Unit = futures.foreach(_.await)