Skip to content

Instantly share code, notes, and snippets.

@jhalterman
Created November 20, 2015 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhalterman/f361d57da42571a85469 to your computer and use it in GitHub Desktop.
Save jhalterman/f361d57da42571a85469 to your computer and use it in GitHub Desktop.
Try until success
(defn try-until-success
"Accepts a try-fn to try a failure-fn to call upon failure, supplying the failure/exception. The try-fn is retried
until no failure is thrown."
[try-fn failure-fn]
(loop []
(if-let [result (try
(try-fn)
(catch Exception e
(failure-fn e)
nil))]
result
(recur))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment