Skip to content

Instantly share code, notes, and snippets.

@amalloy
Forked from dgrnbrg/gist:1996228
Created March 7, 2012 21:29
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 amalloy/1996359 to your computer and use it in GitHub Desktop.
Save amalloy/1996359 to your computer and use it in GitHub Desktop.
Rate limit clojure fn
(defn rate-limit [interval s]
(let [cache (atom {})]
(for [x s
:let [t (System/currentTimeMillis)]
:when (< (+ (get @cache x 0) interval) t)]
(do (swap! cache assoc x t)
x))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment