object RealFun {
def computationA: String = {
"asdf" + "ibjmaretg"
}
def computationB: Int = {
(25 * 342 + 12) * 2
}
def computationC(x: String, y: Int): Double = {
(x.length + y) * 0.3
}
def main(args: Array[String]) : Unit = {
implicit val defaultEC = ExecutionContext.Implicits.global
val ec1:ExecutionContext = ...
val ec2:ExecutionContext = ...
val ec3:ExecutionContext = ...
val fx5 = Future(computationA)(ec1)
val fy5 = Future(computationB)(ec1)
// 1. What I really want is
// val fz5 = fx5.flatMap(x1 => fy5.map( y1 => computationC(x1, y1) )(ec3))(ec2)
// 2. What I do, but which still uses defaultEC for flatMap
val fz5 = (for {
x1 <- fx5
y1 <- fy5 // requires implicit execution context
} yield computationC(x1, y1))(ec2)
// 2. in desugared version
// val fz5 = fx5.flatMap(x1 => fy5.map( y1 => computationC(x1, y1) )(defaultEC))(ec2)
// Can 1. be expressed by a for comprehension?
}
}