Exercises
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.
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 thetimeout
method defined in this chapter.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...