This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-23
Channels
- # announcements (2)
- # babashka (25)
- # beginners (33)
- # biff (13)
- # calva (13)
- # clerk (82)
- # clj-commons (3)
- # clj-kondo (8)
- # clj-on-windows (23)
- # cljdoc (6)
- # clojure (16)
- # clojure-belgium (1)
- # clojure-dev (58)
- # clojure-europe (53)
- # clojure-nl (1)
- # clojure-norway (15)
- # clojure-uk (2)
- # clojurescript (17)
- # core-async (5)
- # cursive (6)
- # datahike (1)
- # datomic (8)
- # emacs (25)
- # etaoin (21)
- # events (4)
- # graalvm (33)
- # honeysql (7)
- # hyperfiddle (1)
- # lsp (49)
- # luminus (4)
- # malli (18)
- # off-topic (63)
- # reagent (11)
- # releases (1)
- # shadow-cljs (200)
- # timbre (1)
- # tools-build (17)
Hey team, consider this fn:
(defn foo-blocking [inputs]
(->> inputs
(mapv <do-work)
(mapv #(<!! %))))
What would be the idiomatic way to make foo non-blocking? I want to wrap a go-routine and use <!
instead of <!!
, but I am not sure how to achieve:
"Do work, then return the results in the order of the inputs".
If I use something like (a/into (a/merge
, order would not be respected.Looking Pipelines are interesteing! I got it to work like this:
(defn <foo [ctx inputs]
(let [out (a/chan)
xf (fn [input out*]
(a/pipe (<do-work ctx input) out*))]
(a/pipeline-async 3 out xf (a/to-chan inputs))
(ua/?into [] out)))
This feels like there's still implementation details. I could abstract it into something, but I wonder if this is already done.
Are there any favorite references / books ya'll would recommend?Update: @UCPGSBNQ4 your suggestion for map does the trick too! In the docs it "set of first items", which made me think the list would be unordered. But that is not the case. One more way to write it:
(defn <foo [inputs]
(->> inputs
(map <do-work)
(a/map vector)))
👍 2