Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7676367320
Fetching contributors…

Cannot retrieve contributors at this time

31 lines (25 sloc) 0.708 kb
;;define agents
(def counter (agent 0))
;;deference
(println @counter)
;;send and send-off,await
(send counter inc)
(send-off counter + 10)
(await counter)
(println @counter)
;;in transacton
(def backup-agent (agent "output/messages-backup.clj" ))
(def messages (ref []))
(defn add-message-with-backup [msg]
(dosync
(let [snapshot (commute messages conj msg)]
(send-off backup-agent (fn [filename]
(spit filename snapshot)
filename))
snapshot)))
(add-message-with-backup "one")
(add-message-with-backup "two")
(add-message-with-backup "three")
(await backup-agent)
;;shutdown
(shutdown-agents)
Jump to Line
Something went wrong with that request. Please try again.