Java Future. , , . , Future . ExecutionException, . deref Clojure.
, -:
(defn die [] (throw (RuntimeException.)))
, :
user=> (def x (future (die)))
; Note: No exception here
user=> @x
RuntimeException user/die (NO_SOURCE_FILE:1)
; Bam! Exception thrown on deref, think of it as
; ExecutionException when getting failed future value in Java
, deref:
user=> (def x (future (die)))
(try @x (catch Exception e (println "Caught ya")))
Caught ya
nil
:
user=> (def x
Caught ya
user=> @x
"Something"
, "Caught ya" , , deref. deref , catch .
, - , Java-.