The easiest way to consume a successful Future-- or rather, get the value inside the Future-- is to use the map
method. Suppose some code calls the divide
method of the FutureDivider
object from the "Creating a Future" example. What would the code need to look like to get the quotient of a
over b
?
object Calculator {
def calculateAndReport(a: Int, b: Int) = {
val eventualQuotient = FutureDivider divide(a, b)
eventualQuotient map {
quotient => println(quotient)
}
}
}