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]
(post-event-to *evq* event))
(defn handle-next-event [evq & dispatchersInit]
(defn handle-next-event [evq & dispatchers]
(dosync (let [queueold @evq]
(if (seq queueold)
(let [queuenew (pop queueold) event (peek queueold)]
(loop [dispatchers dispatchersInit]
(if (seq dispatchers)
(do
((first dispatchers) event)
(recur (next dispatchers)))
(do
(ref-set evq queuenew)
true))))
(doseq [dispatcher dispatchers]
(dispatcher event))
(ref-set evq queuenew)
true)
false))))
(defn handle-events [evq & dispatchers]
(loop [more-events true]
(if more-events (recur (apply handle-next-event evq dispatchers)))))
(defn get-evq [] *evq*)
(defn get-evq [] *evq*)