Created
February 22, 2022 16:34
-
-
Save jaidetree/80d428cf65b5006eb60d90caefefbcd5 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-redefs-async | |
[bindings & body] | |
(let [names (take-nth 2 bindings) | |
vals (take-nth 2 (drop 1 bindings)) | |
orig-val-syms (map (comp gensym #(str % "-orig-val__") name) names) | |
temp-val-syms (map (comp gensym #(str % "-temp-val__") name) names) | |
binds (map vector names temp-val-syms) | |
resets (reverse (map vector names orig-val-syms)) | |
bind-value (fn [[k v]] (list 'set! k v))] | |
`(let [~@(interleave orig-val-syms names) | |
~@(interleave temp-val-syms vals)] | |
~@(map bind-value binds) | |
(promesa.core/-> (promesa.core/do! ~@body) | |
(promesa.core/finally | |
(fn [] | |
~@(map bind-value resets))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment