Finagle By Twitter Engineer @ Knoldus
- 7. A brave new world ...
Typesafe
Expressive
Performant
(thank you JVM)
...
- 9. Synchronous Futures
def piDigit ( n : Int ) : Int def piDigit ( n : Int ) : Future[Int]
println ( piDigit ( 100 ) ) piDigit ( 100 ) onSuccess println
- 11. Synchronous Futures
def piDigit ( n : Int ) : Int def piDigit ( n : Int ) : Future[Int]
println ( piDigit ( 100 ) ) piDigit ( 100 ) onSuccess println
println ( piDigit ( 100 ) * 10 ) ) piDigit ( 100 ) map { _ * 10 } onSuccess println
println ( piDigit ( piDigit ( 100 ) ) ) piDigit ( 100 ) flatMap piDigit onSuccess println
println ( ( 0 to 100 ) map piDigit ) Future.collect {
( 0 to 100 ) map piDigit
} onSuccess println
- 15. trait UserService {
def getByUserId( userId : Long ) : Future [ User ]
def getByScreenName( screenName: String ) : Future [ User ]
}
trait TweetService {
def findByUserId( userId : Long ) : Future [ Seq[ Tweet ] ]
}
- 16. trait UserTweetService {
val userService : UserService
val tweetService : TweetService
def findUserAndTweets(
userId : Long
) : Future [ ( User, Seq[Tweet] ) ] =
Future.join (
userService.findByUserId( userId ),
tweetService.findByUserId( userId )
)
}
}
1
4
2 3 2 3
- 17. trait ScreenNameTweetService {
val userService : UserService
val tweetService : TweetService
def findByScreenName(
screenName: String
) : Future [ Seq[Tweet] ] = {
userService.findByScreenName( screenName ) flatMap {
user => tweetService.findByUserId( user.id )
}
}
}
1
6
2 3 4 5
- 19. val someService = Http.client(“inet!google.com:80”)
val anotherService =
Http.client(
“zk!myzkhost.mycompany.com:2181!/my/zk/path”
)
Address Resolution