Add thread-safe printer
This commit is contained in:
parent
fd1f9bddef
commit
75b58d58a3
1 changed files with 16 additions and 1 deletions
|
@ -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))))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue