Promise Me a Result

The separating effect of immutability and per-thread dynamic binding means that we don’t have to worry quite so much about one thread accidentally interfering with the operation of another, which is a great first step. But it’s only a first step. Having separated our threads for their own safety, we now need to figure out how to get them to work together. Sometimes this isn’t a problem. Some threads are born to silently do a job and silently expire:

 ;; Delete a file in the background.
 
 (.start (Thread. #(.delete (java.io.File. ​"temp-titles.txt"​))))

But more often we want some kind of result back from the thread we just fired off. How many copies did we sell? And what was the revenue? Or simply, Is this thread done? ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.