Last active
June 28, 2018 13:10
-
-
Save lasiltan/2459d6b7f7bf3eece8d7d755d8f4e9fb to your computer and use it in GitHub Desktop.
Clojure - retry function
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 defnretryable [fname args & body] | |
`(def ~fname (fn ~args (loop [n# 5] | |
(when-not (neg-int? n#) | |
(if-let [result# (try [~@body] | |
(catch Exception e# | |
(if (zero? n#) | |
(throw e#) | |
(println "Retry " ~fname))))] | |
(last result#) | |
(recur (dec n#)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment