The Scala Future
In this section, we will discuss the Scala Future. Let's start by defining this component.
What is a Future in Scala?
In Scala, a Future is an object that represents a computation unit. It has some value at some point in the future. In other words, it is a programming construct in Scala used to write concurrency programs very easily. When a Future finishes its computation, we say that the Future is completed. However, it may be completed either successfully, or unsuccessfully.
If a Future is completed successfully, it has some computed value. If it has failed or completed unsuccessfully, it has some error.
The Scala Future API
Future[T]
contains a computation unit of type T
. This computation is done sometime in the future, either successfully or not.
What is a computation unit?
A computation unit is a block of code (which is used to perform a task or calculate some value and so on). Generally, this computation unit runs synchronously. If we place this computation unit in the Future...