The relationship between Scala Future components
As we know, the Scala Future API is used to write asynchronous programs. It has three main components—Future, Promise, and ExecutionContext
.
Let's discuss the relationship and differences between these components. The following diagram shows how the Scala Future API components work together:

As shown in the preceding diagram, Future[T]
contains a computation task of type T
. Promise[T]
executes that computation task T
in ExecutionContext
and writes the results back into the Future[T]
.
Differences between a Future and a Promise
In Scala, a Future and a Promise have the following differences:
- A Promise is used to compute a value, whereas a Future is used to read that value
- A Promise is used write the value, whereas a Future is a read-only object
- Once a Promise is completed, we cannot change its value, it becomes immutable
- Once a Future is completed, we cannot change its value, it becomes immutable
- A Future is for querying data and a Promise is for writing...