January 2017
Intermediate to advanced
565 pages
13h 46m
English
If you have been using Java for a while, you might know the java.util.concurrent.Future class, this is Clojure's implementation of futures and it is extremely similar to Java, only a bit simpler. Its interface and usage are almost identical to promises with a very important difference, when using futures everything will run in a different thread automatically.
Let's see a simple example using futures, in any REPL do the following:
(def f (future (Thread/sleep 20000) "Hello world")) (println @f)
Your REPL should freeze for 20 seconds and then print Hello world.
Futures are also cached, so you only need to pay once for the cost of calculation and then you can use them any number of times you want.
At first glance, futures look much easier ...
Read now
Unlock full access