I have funtion which is calling computeParallel() function which is calling 3 Futures F1,F2,F3 and returning String as return type.
def computeParallel():String =
{
val f1 = Future { "ss" }
val f2 = Future { "sss" }
val f3 = Future { "ssss" }
val result: Future[String] = for {
r1 <- f1
r2 <- f2
r3 <- f3
} yield (r1 + r2 + r3)
Await.result(result,scala.concurrent.duration.Duration.Inf)
}
Using Await to collect the Aggregated Results.But People are saying usage of Await is Bad way of coding.
So i have used below one.Which is returning the Unit type.
result.onComplete {
case Success(res) => return res
}
So if return Unit i cannot print anything.
can any help us.Is there anyother way to solve the problem
Thanks in Advance
See Question&Answers more detail:os