Book Image

Learning Concurrent Programming in Scala

By : Aleksandar Prokopec
5 (1)
Book Image

Learning Concurrent Programming in Scala

5 (1)
By: Aleksandar Prokopec

Overview of this book

Table of Contents (18 chapters)
Learning Concurrent Programming in Scala
About the Author
About the Reviewers


The following exercises summarize what we have learned about futures and promises in this chapter, and require implementing custom future factory methods and combinators. Several exercises also deal with several deterministic programming abstractions that were not treated in this chapter, such as single-assignment variables and maps.

  1. Implement a command-line program that asks the user to input a URL of some website, and displays the HTML of that website. Between the time that the user hits ENTER and the time that the HTML is retrieved, the program should repetitively print a . to the standard output every 50 milliseconds, with a two seconds timeout. Use only futures and promises, and avoid the synchronization primitives from the previous chapters. You may reuse the timeout method defined in this chapter.

  2. Implement an abstraction called a single-assignment variable, represented by the IVar class:

    class IVar[T] {
      def apply(): T = ???
      def :=(x: T): Unit = ???

    When created, the IVar...