diff --git a/src/datomish/test_macros.cljc b/src/datomish/test_macros.cljc index f88e3d6c..1f71e78c 100644 --- a/src/datomish/test_macros.cljc +++ b/src/datomish/test_macros.cljc @@ -3,6 +3,7 @@ ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. (ns datomish.test-macros + (:refer-clojure :exclude [with-open]) (:require [datomish.pair-chan])) @@ -35,3 +36,35 @@ ~(with-meta name {:async true}) (let [[v# e#] (clojure.core.async/ [name init ...] + Evaluates body in a try expression with names bound to the values + of the inits, and a finally clause that calls (.close name) on each + name in reverse order." + {:added "1.0"} + [bindings & body] + (assert-args + (vector? bindings) "a vector for its binding" + (even? (count bindings)) "an even number of forms in binding vector") + (cond + (= (count bindings) 0) `(do ~@body) + (symbol? (bindings 0)) `(let ~(subvec bindings 0 2) + (try + (with-open ~(subvec bindings 2) ~@body) + (finally + (. ~(bindings 0) close)))) + :else (throw (java.lang.IllegalArgumentException. + "with-open only allows Symbols in bindings"))))