Skip to content

Instantly share code, notes, and snippets.

@mszajna
Last active July 25, 2023 13:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mszajna/0ccbdfbd10927ff5d9517aaeb319952a to your computer and use it in GitHub Desktop.
Save mszajna/0ccbdfbd10927ff5d9517aaeb319952a to your computer and use it in GitHub Desktop.
(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