closeable-map
closeable-map copied to clipboard
`close-with` doesn't work on Java objects
It uses ::fn
meta and as such needs a Clojure object. The implementation should change so that it attach the fn to the map and not the object.
I think it does qualify as a bug, but it's quite telling that nobody reported it ^_^ Another explanation is nobody actually tried to use ::fn
.
Actually ::closeable-map/fn
is more for custom close function, for example with reporting and so on. In such case indeed a custom function may be added in the metadata of the containing map. However, closeable-map
may be taught to close any object instances by extending the ::closeable-map/close!
method.
(import '(clojure.lang Atom))
(defmethod c/close! Atom [x] (reset! x nil))
(import '(clojure.core.async.impl.protocols Channel))
(defmethod c/close! Channel [x] (async/close! x))
This should be added as examples.
As long as Java objects are concerned, user can make use of the star pattern, that is to say a closeable*
within a closeable-map*
. In effect this does register this Java object in the metadata of the container.
I'm reluctant to change close-with
. Very happy to hear a different opinion about it.