You're viewing version 1.2.0 of future-call. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

future-call

clojure.core

  • (future-call f)
Takes a function of no args and yields a future object that will
invoke the function in another thread, and will cache the result and
return it on all subsequent calls to deref/@. If the computation has
not yet finished, calls to deref/@ will block.

1 Example top

  • ;; future-call is used to implement 'future'.  See examples for 'future'
    ;; for discussion of an undesirable 1-minute wait that can occur before
    ;; your standalone Clojure program exits if you do not use shutdown-agents.
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:5389 top

(defn future-call 
  "Takes a function of no args and yields a future object that will
  invoke the function in another thread, and will cache the result and
  return it on all subsequent calls to deref/@. If the computation has
  not yet finished, calls to deref/@ will block."
  {:added "1.1"}
  [^Callable f]
  (let [fut (.submit clojure.lang.Agent/soloExecutor f)]
    (reify 
     clojure.lang.IDeref 
      (deref [_] (.get fut))
     java.util.concurrent.Future
      (get [_] (.get fut))
      (get [_ timeout unit] (.get fut timeout unit))
      (isCancelled [_] (.isCancelled fut))
      (isDone [_] (.isDone fut))
      (cancel [_ interrupt?] (.cancel fut interrupt?)))))
Vars in clojure.core/future-call: defn deref get let reify
Used in 1 other vars future

Comments top

No comments for future-call. Log in to add a comment.