Skip to content

Instantly share code, notes, and snippets.

; 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]
;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)))