Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Akka Cookbook

You're reading from   Akka Cookbook Recipes for concurrent, fast, and reactive applications

Arrow left icon
Product type Paperback
Published in May 2017
Publisher Packt
ISBN-13 9781785288180
Length 414 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Authors (3):
Arrow left icon
Vivek Mishra Vivek Mishra
Author Profile Icon Vivek Mishra
Vivek Mishra
Piyush Mishra Piyush Mishra
Author Profile Icon Piyush Mishra
Piyush Mishra
Héctor Veiga Ortiz Héctor Veiga Ortiz
Author Profile Icon Héctor Veiga Ortiz
Héctor Veiga Ortiz
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Diving into Akka FREE CHAPTER 2. Supervision and Monitoring 3. Routing Messages 4. Using Futures and Agents 5. Scheduling Actors and Other Utilities 6. Akka Persistence 7. Remoting and Akka Clustering 8. Akka Streams 9. Akka HTTP 10. Understanding Various Akka patterns 11. Microservices with Lagom

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...

  1. Create a simple scala file, say Parallel.scala, in the com.packt.chapter4 package.
  2. Add the following imports to the top of the file:
        import scala.concurrent.ExecutionContext.Implicits.global 
        import scala.concurrent.{Await, Future} 
  1. 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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image