-
-
Save noidi/304b72eb346cdc42898f to your computer and use it in GitHub Desktop.
This file contains 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
(defn concurrency-test2 [] | |
(let [test-atom (atom 0)] | |
(letfn [(make-agent [] | |
(agent 10)) | |
(run-agent [n] | |
(if (zero? n) | |
n | |
(do | |
(send *agent* run-agent) | |
(swap! test-atom inc) | |
(dec n))))] | |
(reset! test-atom 0) | |
(let [agents (repeatedly 50 make-agent)] | |
(doseq [a agents] | |
(send a run-agent)) | |
(apply await agents)) | |
(println @test-atom) | |
(Thread/sleep 100) | |
(println @test-atom)))) | |
(concurrency-test2) | |
; 199 | |
; 500 | |
;= nil | |
(concurrency-test2) | |
; 453 | |
; 500 | |
;= nil | |
(concurrency-test2) | |
; 181 | |
; 500 | |
;= nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment