Álvaro Navarro wrote this interesting short tutorial on Futures in Scala. In it he explains the nuts and bolts of dealing with Futures in Scala and Akka. Futures allow to perform many operations in parallel in an efficient and non-blocking way, but dealing with multiple operations can be a real headache.
In the modern object oriented languages (Java, Scala, Javascript) and frameworks (Akka, Play, Angular, Node.js) exist data structures to handle the asynchrony.
The most relevant are the futures and the promises.
They are also considered useful in several contexts, distributed or not. Some of these ones are:
- Request-response patterns
- Long-running computations
- Database queries
- RPC (Remote Procedure Call)
- Reading data from Sockets
- Input/output data (reading large files from disk)
- Managing timeouts in services, etc.
The Futures are an important powerful abstraction that represents values which may or may not be currently available, but will be available at some point, or an exception if these values are available. The simplest variation includes two time-dependent states:
- Completed/determined: the computation is complete and the future’s value is available
- Incomplete/undetermined: the computation is not yet complete
Find more and code examples in this excellent tutorial!
[Read More]