Start United States USA — software Scala Futures: Concurrency Interpreted!

Scala Futures: Concurrency Interpreted!

189
0
TEILEN

If you are from a Java background, you might be aware of java.util.concurrent.Future. We have better Futures in Scala with Scala.concurrent.Future.
Join the DZone community and get the full member experience. Futures allow us to run values off the main thread and handle values that are running in the background or yet to be executed by mapping them with callbacks. It’s a weary and antagonistic way of writing concurrent code. We have better Futures in Scala with Scala.concurrent. Future. With Scala Futures, we can achieve Futures are immutable by nature and are cached internally. Once a value or exception is assigned, Futures cannot be modified/overwritten (it’s hard to achieve referential transparency). Simple example: Think of ExecutionContext as an administrator who allocates new threads or uses a pooled/current thread (not recommended) to execute Futures and their functions. Without importing ExecutionContext into scope, we cannot execute a future. Global ExecutionContext is used in many situations to dodge the need to create custom a ExecutionContext. The default global ExecutionContext will set the parallelism level to the number of available processors (can be increased).

Continue reading...