O'Reilly logo

Pragmatic Scala by Venkat Subramaniam

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

Making the Net Asset Application Concurrent

The sequential implementation of the net asset application looked up the latest price for each symbol one at a time. The major delay is the time spent waiting for the responses from the web—the network delay. Let’s refactor the previous code so we can make the requests for the latest prices for all the symbols concurrently. When done, we should see a faster response from our net asset application.

To make this application concurrent, well, it’s effortless. Since the ticker symbols are all in a collection, all we have to do is turn the collection into a parallel collection and we’re done! We need to change only one line. In the previous code, change

 
val​ valuesAndWorth = symbolsAndUnits.keys.map ...

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