Add thread-safe printer

This commit is contained in:
Nicholas Kariniemi 2014-10-10 22:15:49 +03:00
parent fd1f9bddef
commit 75b58d58a3

View file

@ -1,7 +1,22 @@
(ns grub.util) (ns grub.util
(:require [grub.diff :as diff]
#+clj [clojure.core.async :as a :refer [<! >! chan go]]
#+cljs [cljs.core.async :as a :refer [<! >! chan]])
#+cljs (:require-macros [grub.macros :refer [log logs]]
[cljs.core.async.macros :refer [go]]))
(defn map-by-key [key coll] (defn map-by-key [key coll]
(->> coll (->> coll
(map (fn [a] [(get a key) a])) (map (fn [a] [(get a key) a]))
(into {}))) (into {})))
(defn printer []
(let [in (chan)]
(go (loop []
(when-let [msg (<! printer)]
#+clj (clojure.pprint/pprint msg)
#+clj (println "-------")
#+cljs (logs msg)
#+cljs (log "-------")
(recur))))))