This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-25
Channels
- # aws (2)
- # bangalore-clj (2)
- # beginners (90)
- # boot (89)
- # bristol-clojurians (1)
- # cider (23)
- # cljs-dev (48)
- # cljsjs (2)
- # cljsrn (3)
- # clojure (118)
- # clojure-argentina (3)
- # clojure-austin (8)
- # clojure-czech (1)
- # clojure-dev (18)
- # clojure-ireland (1)
- # clojure-italy (4)
- # clojure-russia (6)
- # clojure-spec (75)
- # clojure-uk (224)
- # clojurescript (103)
- # core-async (28)
- # cursive (3)
- # datascript (7)
- # datomic (15)
- # dirac (30)
- # emacs (14)
- # events (3)
- # figwheel (1)
- # hispano (1)
- # hoplon (176)
- # lambdaisland (1)
- # lein-figwheel (6)
- # off-topic (21)
- # om (7)
- # onyx (2)
- # pedestal (6)
- # re-frame (4)
- # reagent (15)
- # spacemacs (67)
- # specter (13)
- # testing (9)
- # untangled (65)
- # vim (6)
- # yada (1)
if you have a bunch of go block code executing concurrently, is it possible for one of them to be starved?
But back pressure makes starvation a rather rare occurrence
Does core.async have a range over channels form like golang has?
go-loop might work.
@stuartrexking The doall ..... map
is actually your problem why it hangs
The go
macro won't walk into the anonymous function (here #(>! out %)
) and rewrite the >!
"function call".
@rauh Thanks
I’ll give that a go.
Works great, thanks.
So don’t use anonymous functions in go blocks?
Ah. Great. Thanks.
@stuartrexking Wanted to say thanks for linking to the golang example. In case you’re interested, after using the more primitive way of squaring the ints in the example, here’s a way to do it using a more rich set of tools from the core.async library, namely to-chan
and map
:
(defn square-ints-v2
[start end]
(let [ints (a/to-chan (range start (inc end)))
squares (a/map #(* % %) [ints])]
(go-loop []
(when-let [i (<! squares)]
(println i)
(recur)))))
(square-ints-v2 30 40)
another way, using a transducer and a bit more collection-oriented — btw, core.async gurus, please give me some feedback on whether this type of construct would be typical or not
(defn square-ints-v2
[start end]
(let [square-chan (chan 1 (map #(* % %)))]
(a/onto-chan square-chan (range start (inc end)))
(a/<!! (a/into [] square-chan))))
(run! println (square-ints-v2 30 40))
joshjones: Thanks!
@joshjones async/map
and friends are deprecated, and I definitely see your most recent example as the preferred.
thanks @jgdavey , according to the docs, only the map<
and map>
are actually deprecated (not map
itself)?
i know though that transducers were in part implemented due to having to rewrite mapcat<
, map<
, etc. again for core.async — but it seems that map
itself is a bit of a different animal
But typically I’d see a transducer when you’re mapping values across a channel. I think map
is used when you need to do something with multiple channels
that makes sense — the fact that it takes multiple channels is a bit strange, and I will prefer a transducers-based approach — your feedback is welcome, thanks 🙂
@joshjones yes, I lobbied for Rich to add map
because there are cases where you want one value from each channel to be combined, and that can be solved like this: (async/map vector a b)
and what you get out is [a1 b1] [a2 b2] [a3 b3]