O'Reilly logo

Learning Concurrent Programming in Scala by Aleksandar Prokopec

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Promises

In Chapter 2, Concurrency on the JVM and the Java Memory Model, we implemented an asynchronous method that used a worker thread and a task queue to receive and execute asynchronous computations. That example should have left you with a basic intuition about how the execute method is implemented in execution contexts. You might be wondering how the Future.apply method can return and complete a Future object. We will study promises in this section to answer this question. Promises are objects that can be assigned a value or an exception only once. This is why promises are sometimes also called single-assignment variables. A promise is represented with the Promise[T] type in Scala. To create a promise instance, we use the Promise.apply

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required