clojure.async: "<! not in (go ...) block" error
clojure, core.async
Solution
because `go` blocks can't cross function boundaries I tend to fall back on loop/recur for a lot of these cases. the `(go (loop` pattern is so common that it has a short-hand form in core.async that is useful in cases like this:
user> (require '[clojure.core.async :as async])
user> (async/<!! (let [chans [(async/chan) (async/chan) (async/chan)]]
(doseq [c chans]
(async/go (async/>! c 42)))
(async/go-loop [[f & r] chans result []]
(if f
(recur r (conj result (async/<! f)))
result))))
[42 42 42]
Problem
When I evaluate the following core.async clojurescript code I get an error: "Uncaught Error: <! used not in (go ...) block" ``` (let [chans [(chan)]] (go (doall (for [c chans] (let [x (<! c)] x))))) ``` What am I doing wrong here? It definitely looks like the <! is in the go block.