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
; Copyright 2010 Garth Sheldon-Coulson | |
(defn serf | |
"Returns a new serf with contents x." | |
[x] | |
(agent (ref x))) | |
(defn serf-deref [x] @@x) | |
(defn send* [s f] |
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
;simulates heavy asychronous state change | |
(defn start-frequent-changes [& some-refs] | |
(let [change (fn [value] | |
(cond | |
(pos? value) (inc value) | |
(neg? value) (dec value) | |
:else (identity value)))] | |
(doseq [a-ref some-refs] | |
(future (loop [] (Thread/sleep 200) (dosync (alter a-ref change)) (recur))) |