playground
The code is below:
import concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
var wait1: Future[Unit] = Future.successful(())
def someAsyncFuncOne(): Future[(Int, Int, Int)] =
Future.successful((1, 2, 3))
def someAsyncFuncTwo(tup: (Int, Int, Int)): Future[Unit] =
Future.successful(())
wait1 = someAsyncFuncOne().map { result => // line 12
{
someAsyncFuncTwo(result).map { _ =>
()
}
}
}
def handle(result: (Int, Int, Int)): Future[Unit] = {
someAsyncFuncTwo(result).map { _ =>
()
}
}
wait1 = someAsyncFuncOne().map { // line 26
handle
}
val result = someAsyncFuncOne().map {
handle
}
wait1 = result
The type of result is Future[Future[Unit]]
and the type of wait1 is Future[Unit]
. Apparently, the assign statement wait = result
can not be compiled, but why this two statements of line 12 and line26 can be compiled?