Back

closeable-map* (clj)

(source)

macro

(closeable-map* & body)
Avoid partially open state when an exception is thrown on evaluating inner closeable forms wrapped by `closeable`. Inner forms must return a map. ``` clojure (closeable-map* {:server (closeable* (http/start-server (api config))) :kafka {:consumer (closeable* (kafka-consumer config)) :producer (closeable* (kafka-producer config)) :schema.registry.url "https://localhost"}}) ``` The outcome of this macro `closeable-map*` is one of the following: - Either everything went right, and all inner forms wrapped by `closeable` correctly return a value, then this macro returns an open instance of `CloseableMap`. - Either some inner form wrapped by `closeable` didn't return a closeable object but threw an exception instead. Then all `closeable` forms are closed, and finally the exception is bubbled up. Known (minor) issue: type hint is not acknowledged, you have to tag it yourself with `^CloseableMap` (most precise), `^java.io.Closeable`, or `^java.lang.AutoCloseable` (most generic).

Examples