This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-18
Channels
- # announcements (19)
- # babashka (30)
- # beginners (51)
- # biff (12)
- # calva (20)
- # cider (27)
- # clara (20)
- # clj-kondo (19)
- # clojure (128)
- # clojure-canada (1)
- # clojure-dev (5)
- # clojure-europe (29)
- # clojure-nl (1)
- # clojure-norway (48)
- # clojure-uk (5)
- # clojurescript (6)
- # clr (37)
- # core-async (17)
- # cursive (2)
- # data-oriented-programming (2)
- # datahike (1)
- # datomic (5)
- # emacs (22)
- # exercism (1)
- # funcool (17)
- # humbleui (15)
- # jobs (1)
- # malli (44)
- # off-topic (11)
- # podcasts-discuss (1)
- # pomegranate (1)
- # react (1)
- # remote-jobs (1)
- # shadow-cljs (25)
- # tools-build (12)
- # tools-deps (70)
- # xtdb (24)
I've got a thread of sequence transformations and I need to add one that returns a channel:
(async/go
(->> xs
(sort-by foo)
(partition-by bar)
(map (fn [zs] (async/go (async/<! (some-chan zs)))))))
What's the best way to collect the result from each chan? I've tried async/merge
but that is either literally merging the results or only returning the last one.merge will get you a channel where everything read from a collections of channels will be published
its more complicated, but if you feed the partitions into a channel using one of the to-chans you can use pipeline-async to replace the map and have the output be a single channel in order that you can then use into on
I was just wondering the same today. Thanks for the tip, hiredman!
Something like this?
(a/pipeline-async 15 out-chan
(fn [v ch] (a/go (a/>! ch (a/<! v)) (a/close! ch)))
(a/to-chan! chs))
?Mine turned out like this:
(async/go
(let [error-ch (async/chan)
out-ch (async/chan)
results-ch (async/into [] out-ch)
work-ch (->> (sort-by foo xs)
(partition-by bar)
(async/to-chan))]
(async/pipeline-async 2
out-ch
(fn [work-partittion ch]
(-> (chan-returning-work-fn work-partition error-ch)
(async/pipe ch)))
work-ch)
(async/alt!
error-ch ([e] e)
results-ch ([result] result))))
ah, old good a/pipe! thanks!
Is there a built-in function that does this?
(async/<! (async/into [] chs))
Similarly, a lazy version? I find myself writing the above quite often for tests / debugging.