С помощью этого метода
def taskA(): Future[Unit] = Future {
Future {
print("Starting nested future")
Thread.sleep(3000)
print("Finished nested future")
}
print("starting outer future")
Thread.sleep(1000)
print("finished outer future")
}
Можно ли ждать завершения вложенного будущего, прежде чем фактически завершить внешнее будущее?Вот как я выполняю эту программу:
print("Starting program")
val futureA = taskA()
futureA onComplete{
case Success(_) => print("future suceeded")
case Failure(_) => print("not able to execute future")
}
Await.result(futureA, Duration.Inf)
Это вывод моей консоли:
15:18:52.357 [main] Starting program
15:18:52.563 [scala-execution-context-global-13] Starting nested future
15:18:52.564 [scala-execution-context-global-12] starting outer future
15:18:53.564 [scala-execution-context-global-12] finished outer future
15:18:53.566 [scala-execution-context-global-12] future suceeded
Process finished with exit code 0