Skip to content

Instantly share code, notes, and snippets.

@zane
Last active August 29, 2015 14:03
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 zane/58e3c77951eaa5159f26 to your computer and use it in GitHub Desktop.
Save zane/58e3c77951eaa5159f26 to your computer and use it in GitHub Desktop.
(defn backoff-seq
([xs]
(backoff-seq xs 0))
([xs backoff]
(lazy-seq
(try (if-let [xs (seq xs)]
(cons (first xs) (backoff-seq (rest xs) (Math/floor (/ backoff 2))))
nil)
(catch MyExceptionHere e
(Thread/sleep (* backoff 1000))
(backoff-seq xs (* backoff 2 )))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment