I don't understand why this example, taken from here, is blocking
import java.util.concurrent.Executors
import scala.concurrent._
import scala.concurrent.duration.Duration
object Main {
def main(args: Array[String]) {
println("Start")
implicit val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(1))
println("Made ec")
def addOne(x: Int) = {
println("Executing addOne")
Future(x)
}
def multiply(x: Int, y: Int): Future[Int] = Future {
val a = addOne(x)
val b = addOne(y)
val result: Future[Int] = for (r1 <- a; r2 <- b) yield r1 * r2
println("Got result")
val awaitedResult: Int = Await.result(result, Duration.Inf)
println("awaitedResult = " + awaitedResult)
awaitedResult
}
val mult: Future[Int] = multiply(2,2)
val multResult: Int = Await.result(mult, Duration.Inf)
println("Result of mult = " + multResult)
}
}
Output of IntelliJ Scala Project:
Connected to the target VM, address: '127.0.0.1:36346', transport: 'socket'
Start
Made ec
Executing addOne
Executing addOne
Got result
awaitedResult = 4
Result of mult = 4
Disconnected from the target VM, address: '127.0.0.1:36346', transport: 'socket'
Process finished with exit code 130
Note:
Hot Swap failed Main: hierarchy change not implemented;
Main: Operation not supported by VM
The weird thing is that in the IntelliJ console, I see the answer, 4, but I have to click the red "stop" button because it won't terminate.