Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn retry
- [op checker & {:keys [pre-retry times error-message]
- :or {pre-retry #(), times 1, error-message "Retries exhausted"}}]
- (let [[result e] (try [(op) nil] (catch Exception e [nil e]))]
- (if (and (nil? e) (checker result))
- result
- (if (pos? times)
- (do (pre-retry)
- (recur op checker {:pre-retry pre-retry
- :times (dec times)
- :error-message error-message}))
- (or e (Exception. error-message))))))
Advertisement
Add Comment
Please, Sign In to add comment