(ns grub.async (:require [clojure.core.async :as async :refer [! chan go put! alts!]])) (defmacro go-loop [& body] `(clojure.core.async/go (while true ~@body))) (defn put-all! [cs x] (doseq [c cs] (put! c x))) (defn fan-out [in cs-or-n] (let [cs (if (number? cs-or-n) (repeatedly cs-or-n chan) cs-or-n)] (go (loop [] (let [x (! c x))) c)) (defn map-chan ([f source] (map-chan (chan) f source)) ([c f source] (go-loop (>! c (f (! c v)))) c)) (defn do-chan! [f source] (go-loop (let [v (! out v) (f v))) out))