From 3f9beb1699083a820db5b6d0b70c8073457a7d3a Mon Sep 17 00:00:00 2001 From: Logan Linn Date: Thu, 24 Feb 2022 23:24:24 -0800 Subject: [PATCH] respect java.lang.AutoCloseable the README suggests `AutoCloseable` is respected, but currently is not. reproduction: ``` dev=> (require '[juxt.clip.core :as clip]) nil dev=> (def config #_=> {:components #_=> {:a {:start #(reify java.lang.AutoCloseable #_=> (close [_] #_=> (println "close ")))} #_=> :b {:start #(reify java.io.Closeable #_=> (close [_] #_=> (println "close ")))}}}) #_=> dev=> (clip/stop config (clip/start config)) close {:a nil, :b nil} ``` makes the following improvements: - switch `java.io.Closeable` to superinterface, `java.lang.AutoCloseable`. - switch from `(isa? (class x) C)` to idiomatic `(instance? C x)`. --- src/juxt/clip/impl/core.cljc | 6 +++--- test/juxt/clip/core_test.cljc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/juxt/clip/impl/core.cljc b/src/juxt/clip/impl/core.cljc index dc96389..52248cf 100644 --- a/src/juxt/clip/impl/core.cljc +++ b/src/juxt/clip/impl/core.cljc @@ -218,8 +218,8 @@ stop-code (evaluator stop-code {'this inst}) #?@(:clj - [(isa? (class inst) java.io.Closeable) - (.close ^java.io.Closeable inst)]))) + [(instance? java.lang.AutoCloseable inst) + (.close ^java.lang.AutoCloseable inst)]))) (defn component-chain [system] @@ -235,7 +235,7 @@ (defn StatefulThing [] (reify - java.io.Closeable + java.lang.AutoCloseable (close [this] (println "Closing a stateful thing")))) (def system2 diff --git a/test/juxt/clip/core_test.cljc b/test/juxt/clip/core_test.cljc index 0ae619a..0dd7f7f 100644 --- a/test/juxt/clip/core_test.cljc +++ b/test/juxt/clip/core_test.cljc @@ -115,7 +115,7 @@ (let [closed? (atom false) auto-closable (reify - java.io.Closeable + java.lang.AutoCloseable (close [this] (reset! closed? true)))] (clip/stop {:components