This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # 100-days-of-code (16)
- # beginners (67)
- # boot (5)
- # cljs-dev (52)
- # cljsjs (2)
- # clojure (94)
- # clojure-spec (34)
- # clojure-uk (10)
- # clojurescript (91)
- # clojutre (1)
- # core-async (20)
- # cursive (5)
- # datomic (1)
- # figwheel-main (70)
- # fulcro (101)
- # hyperfiddle (3)
- # jobs (1)
- # klipse (16)
- # mount (1)
- # nrepl (3)
- # off-topic (24)
- # portkey (39)
- # re-frame (4)
- # reitit (1)
- # shadow-cljs (3)
- # spacemacs (9)
- # tools-deps (5)
@clarkenciel I tried that but it doesn't seem to work either... since I was curious about @xiongtx’s question 🙂
Ah, the following seems to work:
(defn consume-chs [chs] (go-loop  (let [vsc (async/map vector chs) vs (<! vsc)] (when (every? some? vs) (println vs) (recur)))))
Hmm, that seems to drop every other value put into the channels (so I'm probably doing something wrong).
This doesn't solve the skipping problem, but I think you could get ride of the
vector argument in your example @seancorfield. given the original sample I think the channels have iterables on them. I reckon my take didn't work because the
<! function doesn't do anything on its own and is primarily a bit of syntax that the go macro uses to figure out where to do thread parking. It looks like
(async/map identity chs) would accomplish the same goal though.
(async/map identity chs) doesn't work -- I tried that first. What
async/map does is apply the function across all the channels -- so you need a function that takes as many arguments as there are channels.
identity only takes one argument so you'll get an arity error as soon as you have more than one channel in
maybe you want
(take 1 (async/map vector chans)) - otherwise it would make a vector of every first item, vector of every second item, etc.
async/map returns a channel containing the result of applying the function across all the channels.
I spent quite a lot of time in the REPL with
core.async last night trying to figure it out.
It looked like @xiongtx wanted a vector of values back from a vector of channels -- hence the
(every? some? vs) call...
I just don't know why my code was dropping every other value (the values it did get were vectors of values from all the channels -- a vector of the first values followed by a vector of the third values, then fifth...