The futures are running concurrently because they have been started concurrently :).
To run them sequentially you need to use flatMap:
Future { println("startFirst");
Thread.sleep(3000);
println("stopFirst")
}.flatMap{
_ => Future {
println("startSecond");
Thread.sleep(1000);
println("stopSecond")
}
}
Future.sequence just turns Seq[Future[T]] => Future[Seq[T]]
which means gather results of all already started futures and put it in future .
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…