Created
June 6, 2017 04:52
-
-
Save bolasblack/df436ebaee96f1ef49156e692be2473f to your computer and use it in GitHub Desktop.
[limit concurrency operation with core.async]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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