The ExecutionContext
parameter is actually implicit
. That means you can:
import scala.concurrent.ExecutionContext
implicit val context = ExecutionContext.fromExecutor(//etc)
for {
f <- future1
g <- future2
} yield {
// code to be executed after future1 onSuccess and future2 onSuccess
// What ExecutionContext runs this code?: the one above.
}
You also have a default, namely scala.concurrent.ExecutionContext.Implicits.global
.
This has as many threads as the processors on the running machine.
It won't be used by all Futures by default, you still have to import it.
Update: If you really want to specifiy, although it's not recommended, you can unwrap the for yield
val combined = futureA.flatMap(x => futureB)(context)