Skip to content

Instantly share code, notes, and snippets.

@lasiltan
Last active June 28, 2018 13:10
Show Gist options
  • Save lasiltan/2459d6b7f7bf3eece8d7d755d8f4e9fb to your computer and use it in GitHub Desktop.
Save lasiltan/2459d6b7f7bf3eece8d7d755d8f4e9fb to your computer and use it in GitHub Desktop.
Clojure - retry function
(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