src/clojurecraft/loops.clj @ aa67f93d6fe4
Handle namedentityspawn packets.
| author | Steve Losh <steve@stevelosh.com> |
|---|---|
| date | Fri, 26 Aug 2011 20:12:29 -0400 |
| parents | 7aa6da5b1d8b |
| children | 7942222da830 |
(ns clojurecraft.loops (:use [clojurecraft.actions :only [handle-action-group]])) ; Loops ---------------------------------------------------------------------------- (defn- run-loop [bot function sleep-ms loop-id] (while (and (nil? (:exit @(:connection bot))) (@(:loops bot) loop-id)) (handle-action-group bot ((deref function) bot)) (Thread/sleep sleep-ms)) (dosync (alter (:loops bot) dissoc loop-id))) (defn remove-loop [bot loop-id] (dosync (alter (:loops bot) assoc loop-id nil))) (defn add-loop [bot function sleep-ms loop-id] (dosync (alter (:loops bot) assoc loop-id :running)) (.start (Thread. #(run-loop bot function sleep-ms loop-id))))