Refactor: use go-loop macro

This commit is contained in:
Nicholas Kariniemi 2013-07-31 18:50:33 +03:00
parent 8891e402d0
commit 1b2f67a961
2 changed files with 17 additions and 17 deletions

View file

@ -3,7 +3,7 @@
[cljs.core.async :as async :refer [<! >! chan close! timeout]])
(:require-macros [dommy.macros :refer [deftemplate sel1 node]]
[cljs.core.async.macros :as m :refer [go alt! alts!]]
[grub-client.macros :refer [log]]))
[grub-client.macros :refer [log go-loop]]))
(deftemplate grub-template [grub]
[:tr
@ -60,20 +60,17 @@
(dommy/append! (sel1 :#grubList) (grub-template grub)))
(defn append-new-grubs [chan]
(go (while true
(let [grub (<! chan)]
(append-new-grub grub)))))
(go-loop (let [grub (<! chan)]
(append-new-grub grub))))
(defn add-grubs-to-list [in]
(go (while true
(let [new-grub (<! in)]
(append-new-grub new-grub)))))
(go-loop (let [new-grub (<! in)]
(append-new-grub new-grub))))
(defn filter-empty-grubs [in]
(let [out (chan)]
(go (while true
(let [grub (<! in)]
(when-not (empty? grub) (>! out grub)))))
(go-loop (let [grub (<! in)]
(when-not (empty? grub) (>! out grub))))
out))
(def websocket* (atom nil))
@ -84,16 +81,14 @@
(let [grub (.-data event)]
(log "Received grub:" grub)
(append-new-grub grub))))
(go (while true
(let [grub (<! chan)]
(.send websocket grub))))))
(go-loop (let [grub (<! chan)]
(.send websocket grub)))))
(defn fan-out [in num-chans]
(let [out-channels (repeatedly num-chans chan)]
(go (while true
(let [x (<! in)]
(go-loop (let [x (<! in)]
(doseq [out out-channels]
(>! out x)))))
(>! out x))))
out-channels))
(defn add-new-grubs-as-they-come []

View file

@ -2,3 +2,8 @@
(defmacro log [& args]
`(.log js/console ~@args))
(defmacro go-loop [& body]
`(cljs.core.async.macros/go
(while true
~@body)))