For a, B, and C, the Akka is automatically executed sequentially by default, but for database operations we want to execute a few operations in order, and we need to use syntax to declare
There are two ways to declare a future relationship, the first is FlatMap, and the second is for
ImportScala.Concurrent.FutureImportScala.Concurrent.ExecutionContext.Implicits.GlobalImportScala.Concurrent.BlockingImportScala.Concurrent.Duration._DefF(Item: Int): Future[Unit] = Future{Print("Waiting" +Item+ "Seconds ...") Console.Flush blocking{Thread.Sleep((Item seconds).Tomillis)}println("Done")}ValFserial=F(4)FlatMap(Res1=F(16 Flatmap (res2 =>< Span class= "PLN" > F (2 FlatMap (res3 => F (8fserial.{case Restry => Println ( "!!!! That ' s a wrap!!!! success= " + Restry.
ValFserial= For {Res1<-F(4);Res2<-F(16 Res3 <- F (2 res4 <- F (8)} yield "did it!" fserial.{case Restry => Println ( "!!!! That ' s a wrap!!!! success= " + Restry.
For can be understood as FLATMAP syntax sugar, from the written code view, for clearer, intuitive
It is important to note that iterator and future cannot be placed in a for loop, then a for loop, either iterator or a future
Scala Akka future sequence execution sequential execution