Creating a simple parallel application using futures
In this recipe, we will create an application that will compute the result in parallel. You will learn how independent operations can be parallelized, which will reduce the running time of a program.
Getting ready
To step through this recipe, we need to import the Hello-Akka
project in the IDE. The rest of the prerequisites are the same as before.
How to do it...
- Create a simple scala file, say
Parallel.scala
, in thecom.packt.chapter4
package. - Add the following imports to the top of the file:
       import scala.concurrent.ExecutionContext.Implicits.global       import scala.concurrent.{Await, Future}
- Create a Scala object, as shown in the following code snippet, which calculates a Fibonacci number:
       object Fib {       def fib(n: Int): Int = {       def fib_tail(n: Int, a: Int, b: Int): Int = n match {       case 0 => a       case _ => fib_tail(n - 1, b, a + b)       }       fib_tail...