1.3.0 permalink Arrow_down_16x16

deref

clojure.core

  • (deref ref)
  • (deref ref timeout-ms timeout-val)
Also reader macro: @ref/@agent/@var/@atom/@delay/@future/@promise. Within a transaction,
returns the in-transaction-value of ref, else returns the
most-recently-committed value of ref. When applied to a var, agent
or atom, returns its current state. When applied to a delay, forces
it if not already forced. When applied to a future, will block if
computation not complete. When applied to a promise, will block
until a value is delivered. The variant taking a timeout can be
used for blocking references (futures and promises), and will return
timeout-val if the timeout (in milliseconds) is reached before a
value is available. See also - realized?.

1 Example top

  • user=> (def a (atom 0))
    #'user/a
    user=> @a
    0
    user=> (deref a)
    0
    
    user=> (def b (ref 1))
    #'user/b
    user=> @b
    1
    user=> (deref b)
    1
    
    user=> (def c (agent 2))
    #'user/c
    user=> @c
    2
    user=> (deref c)
    2
    
    user=> (def d (future 3))
    #'user/d
    user=> @d
    3
    user=> (deref d)
    3
Log in to add / edit an example.

See Also top

  • 0
    clojure.core/atom

    Creates and returns an Atom with an initial value of x and zero or

  • 0
    clojure.core/agent

    Creates and returns an agent with an initial value of state and zer

  • 0
    clojure.core/ref

    Creates and returns a Ref with an initial value of x and zero or mo

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2065 top

(defn deref
  "Also reader macro: @ref/@agent/@var/@atom/@delay/@future/@promise. Within a transaction,
  returns the in-transaction-value of ref, else returns the
  most-recently-committed value of ref. When applied to a var, agent
  or atom, returns its current state. When applied to a delay, forces
  it if not already forced. When applied to a future, will block if
  computation not complete. When applied to a promise, will block
  until a value is delivered.  The variant taking a timeout can be
  used for blocking references (futures and promises), and will return
  timeout-val if the timeout (in milliseconds) is reached before a
  value is available. See also - realized?."
  {:added "1.0"
   :static true}
  ([^clojure.lang.IDeref ref] (.deref ref))
  ([^clojure.lang.IBlockingDeref ref timeout-ms timeout-val] (.deref ref timeout-ms timeout-val)))
Vars in clojure.core/deref:
Used in 0 other vars

Comments top

No comments for deref. Log in to add a comment.