September 2018
Intermediate to advanced
398 pages
9h 43m
English
The Future class in the Scala SDK allows you to run computations asynchronously. We will explore this in more detail in Chapter 6, Online Shopping – Persistence, but in this section, we will explore how it makes use of implicit parameters to provide an execution context.
Open a Scala console and enter the following code. It should create a Future computation that will print the name of the current thread when it gets executed:
scala> import scala.concurrent.Futureimport scala.concurrent.Futurescala> Future(println(Thread.currentThread().getName))
Since we are missing an implicit in our scope, you should see the following error:
<console>:13: error: Cannot find an implicit ExecutionContext. You might passan (implicit ec: ExecutionContext) ...
Read now
Unlock full access