Merge pull request #1 from stumitchell/master
merged stu's added a dispatch-sync
This commit is contained in:
commit
f6ce0dcde9
|
@ -31,16 +31,21 @@
|
||||||
(assert (some? event-v)) ;; nil would close the channel
|
(assert (some? event-v)) ;; nil would close the channel
|
||||||
(put! dispatch-chan event-v))
|
(put! dispatch-chan event-v))
|
||||||
|
|
||||||
|
(defn dispatch-sync
|
||||||
|
"sync version of above that actually does the dispatch"
|
||||||
|
[event-v]
|
||||||
|
(let [event-id (first-in-vector event-v)
|
||||||
|
handler-fn (get @id->fn event-id)]
|
||||||
|
(assert (not (nil? handler-fn)) (str "No event handler registered for event: " event-id ))
|
||||||
|
(handler-fn app-db event-v)))
|
||||||
|
|
||||||
|
|
||||||
(defn- router
|
(defn- router
|
||||||
"route an event, arriving on the dispatch channel, to the right handler"
|
"route an event, arriving on the dispatch channel, to the right handler"
|
||||||
[]
|
[]
|
||||||
(go-loop []
|
(go-loop []
|
||||||
(let [event-v (<! dispatch-chan)
|
(let [event-v (<! dispatch-chan)]
|
||||||
event-id (first-in-vector event-v)
|
(dispatch-sync event-v)
|
||||||
handler-fn (get @id->fn event-id)]
|
|
||||||
(assert (not (nil? handler-fn)) (str "No event handler registered for event: " event-id ))
|
|
||||||
(handler-fn app-db event-v)
|
|
||||||
(recur))))
|
(recur))))
|
||||||
|
|
||||||
(router) ;; run the router loop it
|
(router) ;; run the router loop it
|
||||||
|
|
Loading…
Reference in New Issue