O'Reilly logo

Actors in Scala by Frank Sommers, Philipp Haller

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

5.3 Event-based futures

In Chapter 4, we illustrated how to use futures for result-bearing messages. Some of the methods used to wait for the result of a future rely on the thread-based receive under the hood. While waiting for the result, those methods monopolize the underlying worker thread. We can also wait for a future in an event-based way with react.

For example, suppose we want to render a summary of all images linked from a web page at a given URL. We can render each image individually once the image has finished downloading. To increase the application's throughput, each image is downloaded by its own actor. Since each downloading actor performs a result-bearing task, it is convenient to use futures to keep track of the expected results. ...

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