More idiomatic looping

This commit is contained in:
Jeremy Penner 2013-03-09 09:26:09 -06:00
parent 1118b012f1
commit 492b5393a1

View file

@ -13,22 +13,18 @@
(defn post-event [event] (defn post-event [event]
(post-event-to *evq* event)) (post-event-to *evq* event))
(defn handle-next-event [evq & dispatchersInit] (defn handle-next-event [evq & dispatchers]
(dosync (let [queueold @evq] (dosync (let [queueold @evq]
(if (seq queueold) (if (seq queueold)
(let [queuenew (pop queueold) event (peek queueold)] (let [queuenew (pop queueold) event (peek queueold)]
(loop [dispatchers dispatchersInit] (doseq [dispatcher dispatchers]
(if (seq dispatchers) (dispatcher event))
(do (ref-set evq queuenew)
((first dispatchers) event) true)
(recur (next dispatchers)))
(do
(ref-set evq queuenew)
true))))
false)))) false))))
(defn handle-events [evq & dispatchers] (defn handle-events [evq & dispatchers]
(loop [more-events true] (loop [more-events true]
(if more-events (recur (apply handle-next-event evq dispatchers))))) (if more-events (recur (apply handle-next-event evq dispatchers)))))
(defn get-evq [] *evq*) (defn get-evq [] *evq*)