diff --git a/src-cljs/grub_client/core.cljs b/src-cljs/grub_client/core.cljs index e5d0d40..965d36c 100644 --- a/src-cljs/grub_client/core.cljs +++ b/src-cljs/grub_client/core.cljs @@ -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 (! out grub))))) + (go-loop (let [grub (! out grub)))) out)) (def websocket* (atom nil)) @@ -84,17 +81,15 @@ (let [grub (.-data event)] (log "Received grub:" grub) (append-new-grub grub)))) - (go (while true - (let [grub (! out x))))) - out-channels)) + (>! out x)))) + out-channels)) (defn add-new-grubs-as-they-come [] (let [added-grubs (get-added-grubs) diff --git a/src-cljs/grub_client/macros.clj b/src-cljs/grub_client/macros.clj index 83127b7..5c0f1bb 100644 --- a/src-cljs/grub_client/macros.clj +++ b/src-cljs/grub_client/macros.clj @@ -2,3 +2,8 @@ (defmacro log [& args] `(.log js/console ~@args)) + +(defmacro go-loop [& body] + `(cljs.core.async.macros/go + (while true + ~@body)))