I have a call that returns a Future. However, I need to make n calls so I will get back n futures. I am wondering how I would get the futures to all resolve before proceeding (w
I take it that you want to do something after the Futures are finished ,eg. a callback, without blocking the original call? Then you should do something like this:
val futures = for (...) yield {
future {
...
}
}
val f = Future sequence futures.toList
f onComplete {
case Success(results) => for (result <- results) doSomething(result)
case Failure(t) => println("An error has occured: " + t.getMessage)
}
http://docs.scala-lang.org/overviews/core/futures.html
So you don't block with an await call, but you still wait for all Futures to complete and then do something on all results. The key aspects is using Future.sequence to join a lot of futures together and then to use a callback to act on the result.