Skip to content

Instantly share code, notes, and snippets.

@r2p2
Created October 17, 2010 09:14
Show Gist options
  • Save r2p2/630682 to your computer and use it in GitHub Desktop.
Save r2p2/630682 to your computer and use it in GitHub Desktop.
Mal wieder erste Gehversuche in Clojure.
(defn kill-process [process-channel]
(send process-channel (fn [a] "stop")))
(defn engine-loop [channel state process-list]
(loop [my-state state
my-process-list process-list]
(await channel)
(let [channel-value (deref channel)]
(do
(send channel (fn [a] "idle"))
(case channel-value
"start" (do
(println "wfe is starting")
(recur "running" my-process-list))
"stop" (do
(println "wfe is going down")
(println "killing all open processes")
(map kill-process my-process-list)
(recur "stopping" my-process-list))
"idle" (if (and
(.equals "stopping" my-state)
(nil? my-process-list))
(println "wfe is now offline")
(do
(. Thread (sleep 50))
(recur my-state my-process-list)))
(throw "Unknown Agent State."))))))
(defn start []
(let [engine_channel (agent "start")]
(do
(.start (Thread. (fn [] (engine-loop engine_channel "stopped" (seq ())))))
engine_channel)))
(defn stop [channel]
(send channel (fn [a] "stop")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment