Last active
July 25, 2023 13:49
-
-
Save mszajna/0ccbdfbd10927ff5d9517aaeb319952a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro with-open* [bindings & body] | |
(let [[sym exp & others] bindings] | |
(if sym | |
`(let [~sym ~exp | |
result# (try | |
(with-open* [~@others] ~@body) | |
(catch Throwable t# | |
(try | |
(. ~sym close) | |
(catch Throwable t2# | |
(.addSuppressed t# t2#))) | |
(throw t#)))] | |
(. ~sym close) | |
result#) | |
`(do ~@body)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment