Hi all,
If the function executed in a future throws an error it is printed out in the repl immediately. If that function is executed in a future which itself is executed in a future then it isn't.
For example, imagine somebody wrote the following code (please, suspend belief and just accept people do do this when learning Clojure :)):
[code]
;; some silly code
user> (swap! atom inc 0)
ClassCastException clojure.core$atom cannot be cast to clojure.lang.Atom clojure.core/swap! (core.clj:2161)
;; silly code wrapped in a future
user> (future (swap! atom inc 0))
ClassCastException clojure.core$atom cannot be cast to clojure.lang.Atom clojure.core/swap! (core.clj:2161)
;; silly code wrapped in a future wrapped in a future
user> (future (future (swap! atom inc 0)))
#<core$future_call$reify__6267@11e55d39: :pending>
user>
[/code]
My understanding is that future executes its delegate in a separate thread, hence the "(future (swa...))" code prints out the exception almost immediately. I don't understand why the nested future doesn't print out the error though as it should surely be executed almost immediately as well?
Of course, if you dereference the call then it prints out the stack trace.
As to why you would want a future in a future...that is a different kettle of fish :).