You're viewing version 1.2.0 of io!. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (io! & body)
If an io! block occurs in a transaction, throws an
IllegalStateException, else runs body in an implicit do. If the
first expression in body is a literal string, will use that as the
exception message.

1 Example top

  • user=> (def a (ref 0))
    #'user/a
    
    user=> (dosync
             (io! (println "hello"))
             (alter a inc))
    IllegalStateException I/O in transaction
    
    user=> (dosync
             (println "hello")
             (alter a inc))
    "hello"
    1
    
    user=> (defn fn-with-io []
             (io! (println "hello")))
    #'user/fn-with-io
    
    user=> (dosync
             (fn-with-io)
             (alter a inc))
    IllegalStateException I/O in transaction
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:1920 top

(defmacro io!
  "If an io! block occurs in a transaction, throws an
  IllegalStateException, else runs body in an implicit do. If the
  first expression in body is a literal string, will use that as the
  exception message."
  {:added "1.0"}
  [& body]
  (let [message (when (string? (first body)) (first body))
        body (if message (next body) body)]
    `(if (clojure.lang.LockingTransaction/isRunning)
       (throw (new IllegalStateException ~(or message "I/O in transaction")))
       (do ~@body))))
Vars in clojure.core/io!: defmacro let or concat list seq
Used in 3 other vars await await-for transaction*

Comments top

No comments for io!. Log in to add a comment.