Created
August 8, 2016 06:25
-
-
Save JonathanGTH/afac4372407d275e750671e636390004 to your computer and use it in GitHub Desktop.
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 open-for-discussion? (atom true)) | |
(def discussion-count (agent 0)) | |
(def discussion-board (ref [])) | |
(def discussion-board-count 3) | |
(defn open-discussion [duration] | |
(do (Thread/sleep duration) (swap! open-for-discussion? not))) | |
(defn add-discussion [] | |
(future | |
(while @open-for-discussion? | |
(println "discussion-board: " @discussion-board-count) | |
(dosync | |
(< (count (ensure discussion-board)) discussion-board-count) | |
(alter discussion-board conj :board-member))) | |
(Thread/sleep (+ 5 (rand-int 21))))) | |
(defn get-next-discussion [] | |
(dosync | |
(let [next-dicussion (first (ensure discussion-board))] | |
(when next-discussion (alter discussion-board rest) next-discussion)))) | |
(defn get-submission [] | |
(future | |
(while @open-for-dicussion? | |
(when-let [next-discussion (get-next-discussion)] | |
(Thread/sleep 20) | |
(send discussion-count inc))))) | |
(do | |
(get-submission) | |
(add-discussion) | |
(println "Open discussion board for 10 minutes") | |
(open-discussion 10000) | |
(println "Number of Posts: " @discussion-count) | |
(System/exit 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment