1.3.0 permalink Arrow_down_16x16

deliver

clojure.core

  • (deliver promise val)
Alpha - subject to change.
Delivers the supplied value to the promise, releasing any pending
derefs. A subsequent call to deliver on a promise will throw an exception.

2 Examples top

  • user=> (def x (promise))
    #'user/x
    ;; Trying to deref at this point will make your repl wait forever
    
    
    user=> (deliver x 100)
    #<core$promise$reify__5534@4369a50b: 100>
    
    ;; the promise has been delivered, deref x will return immediately
    user=> @x
    100
    
  • ;; Create a promise
    user> (def p (promise))
    #'user/p ; p is our promise
    
    ;; Check if was delivered/realized
    user> (realized? p)
    false ; No yet
    
    ;; Delivering the promise
    user> (deliver p 42)
    #<core$promise$reify__5727@47122d: 42>
    
    ;; Check again if it was delivered
    user> (realized? p)
    true ; Yes!
    
    ;; Deref to see what has been delivered
    user> @p
    42
    
    ;; Note that @ is shorthand for deref
    user> (deref p)
    42
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:6208 top

(defn deliver
  "Alpha - subject to change.
  Delivers the supplied value to the promise, releasing any pending
  derefs. A subsequent call to deliver on a promise will throw an exception."
  {:added "1.1"
   :static true}
  [promise val] (promise val))
Vars in clojure.core/deliver:
Used in 0 other vars

Comments top

1 comment(s) for deliver.

As of Clojure 1.3 deliver does not throw an exception when it is called multiple times on the same promise. See CLJ-1038.

Log in to add a comment.