Created
July 18, 2013 17:47
-
-
Save stuarthalloway/6031376 to your computer and use it in GitHub Desktop.
Possible tweaks to code example at http://swannodette.github.io/2013/07/12/communicating-sequential-processes/
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
;; proposed change #1, objective: make update to q more evident | |
(defn peekn | |
"Returns vector of (up to) n items from the end of vector v" | |
[v n] | |
(if (> (count v) n) | |
(subvec v (- (count v) n)) | |
v)) | |
(let [el (by-id "ex0") | |
out (by-id "ex0-out")] | |
(go (loop [q []] | |
(set-html out (render q)) | |
(recur (-> (conj q (<! c)) (peekn 10)))))) | |
;; proposed change #2, objective: reduce verbosity of loop/recur | |
(go (while true (<! (timeout 250)) (>! c 1))) | |
(go (while true (<! (timeout 1000)) (>! c 2))) | |
(go (while true (<! (timeout 1500)) (>! c 3))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment