For understanding, only syntactic sugar is used and translated to flatMap, as in example 2 .
This means that your code will look something like this:
Future { ??? }.flatMap { profileSync => Future { ??? }.flatMap { earningsSync => Future { ??? }.map { reimbursementSync =>
As you can see, Future
only starts after the previous completion. To get around this, first run your Future
, and then do this for understanding:
val profileSyncFuture = Future { EmployeeLocalServiceUtil.syncProfileInformation() } val earningsSyncFuture = Future { EmployeeLocalServiceUtil.syncEarnings() } val reimbursementSyncFuture = Future { EmployeeLocalServiceUtil.syncReimbursements() } val viewName: Future[String] = for { profileSync <- profileSyncFuture earningsSync <- earningsSyncFuture reimbursementSync <- reimbursementSyncFuture } yield { "employee/view" }
source share