Skip to content

Instantly share code, notes, and snippets.

@bolasblack
Created June 6, 2017 04:52
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 bolasblack/df436ebaee96f1ef49156e692be2473f to your computer and use it in GitHub Desktop.
Save bolasblack/df436ebaee96f1ef49156e692be2473f to your computer and use it in GitHub Desktop.
[limit concurrency operation with core.async]
(def RATE_LIMIT 5)
(defn operate [n]
(println "test-operate" n (.now js/Date))
(async/timeout 1000))
(defn -test []
(let [limit-chan (async/chan (- RATE_LIMIT 1))]
(go (doseq [n (range 20)]
(let [operate-chan (operate n)]
(take! operate-chan #(take! limit-chan identity))
(>! limit-chan operate-chan))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment