Alternative future frameworks
Scala futures and promises API resulted from an attempt to consolidate several different APIs for asynchronous programming, among them, legacy Scala futures, Akka futures, Scalaz futures, and Twitter's Finagle futures. Legacy Scala futures and Akka futures have already converged to the futures and promises APIs that you've learned about so far in this chapter. Finagle's com.twitter.util.Future
type is planned to eventually implement the same interface as scala.concurrent.Future
, while the Scalaz scalaz.concurrent.Future
type implements a slightly different interface. In this section, we give a brief description of Scalaz futures.
To use Scalaz, we add the following dependency to the build.sbt
file:
libraryDependencies += "org.scalaz" %% "scalaz-concurrent" % "7.0.6"
We now encode an asynchronous tombola program using Scalaz. The Future
type in Scalaz does not have the foreach
method. Instead, we use its runAsync
method, which asynchronously runs the future...