On Thu, Aug 30, 2012 at 11:36 PM, Eric Pederson
<eri...@gmail.com> wrote:
Thanks Viktor -
I copied it over got it working after tweaking to make it compatible with Akka 2.0/Scala 2.9.
I ran into the same issue as Timothy from August 11 where you recommended that he do this:
after(1.second, using = system.scheduler)(Future.failed(new java.util.concurrent.TimeoutException("ohnoes"))) either future onComplete {
I needed to make a Akka 2.0 compatible version of either() too:
def eitherFuture[T, U >: T](f1: Future[T], f2: Future[U])(implicit ec: ExecutionContext): Future[U] = {
val p = Promise[U]()
val completePromise = { e: Either[Throwable, U] => p tryComplete e }
f1 onComplete completePromise
f2 onComplete completePromise
p.future
}
Future.firstCompletedOf(Seq(
after(1.second, using = system.scheduler)(Future.failed(new java.util.concurrent.TimeoutException("ohnoes"))),
future
)) onComplete { … }
To be honest, it's not super-intuitive to have to provide your own failed Future and use either(). It would great to add your tip to Timothy to the Scaladoc.
I'll open a ticket about clarifying it in the FAQ/docs!
Cheers,
√
Thanks!