This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Calling first and use next | |
*/ | |
def getEmailAndAccountTuple(fNickname: Future[String]): Future[(String, Option[Long])] = | |
fNickname.flatMap(nickname => { | |
val fEmailAddr = getEmailAddressByNickname(nickname) | |
val fAccountInfo = getAccountInfoByNickname(nickname) | |
fEmailAddr.flatMap(email => fAccountInfo.map(account => (email, account))) | |
}) | |
val start2: Instant = Instant.now | |
val fNickname: Future[String] = getNicknameById(userId) | |
val fUserInfo2 = for { | |
nickname <- fNickname | |
(email, accountInfo) <- getEmailAndAccountTuple(fNickname) | |
} yield UserInfo(userId, nickname, email, accountInfo) | |
val userInfo2 = Await.result(fUserInfo2, 10 second) | |
val end2: Instant = Instant.now | |
println(printInterval(userInfo2, start2, end2)) // UserInfo(31337,ktz,helloworld@example.com,None) take 5 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment