This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-09
Channels
- # announcements (3)
- # asami (1)
- # babashka (19)
- # beginners (84)
- # calva (3)
- # cider (5)
- # clj-commons (22)
- # clj-kondo (31)
- # cljdoc (4)
- # cljs-dev (5)
- # clojure (65)
- # clojure-australia (1)
- # clojure-europe (44)
- # clojure-nl (2)
- # clojure-uk (2)
- # clojurescript (18)
- # code-reviews (12)
- # conjure (2)
- # core-async (12)
- # data-science (1)
- # datomic (47)
- # deps-new (1)
- # emacs (2)
- # events (4)
- # fulcro (35)
- # integrant (1)
- # jobs (5)
- # jobs-discuss (10)
- # london-clojurians (1)
- # lsp (13)
- # music (1)
- # nextjournal (1)
- # off-topic (11)
- # parinfer (3)
- # pathom (6)
- # polylith (11)
- # portal (41)
- # re-frame (4)
- # reagent (13)
- # reitit (8)
- # remote-jobs (3)
- # sci (18)
- # shadow-cljs (34)
- # spacemacs (3)
- # tools-build (12)
- # tools-deps (6)
- # vim (2)
- # xtdb (7)
Hello! I wanna make several async fetches transform somehow responses from each one and collect all results. Is it's possible with core.async ? Something like this:
;; asynchronously retrieve and transform data
(let [users (xf-users (<! (<get-users)))
articles (xf-articles (<! (<get-articles)))
comments (xf-comments (<! (<get-comments)))
;; somehow wait until all results will available and return
{:users users
:articles articles
:comments comments})
How to do it in a right way?So you want to do the three fetches + transforms in parallel instead of sequentially like you do in your example?
You could do something like this:
(let [users (go (xf-users (<! (<get-users))))
articles (go (xf-articles (<! (<get-articles))))
comments (go (xf-comments (<! (<get-comments))))]
{:users (<! users)
:articles (<! articles)
:comments (<! comments)})
But you need to be careful with the xf-
functions throwing errors - these would go pretty much unnoticed in this snippet (you'd end up with a nil
value but the exception itself would not be logged anywhere by default). There are various ways to deal with this, e.g. you could use https://github.com/alexanderkiel/async-error. Alternatively, since you're apparently familiar with the promise-based approach, you could check whether https://github.com/funcool/promesa might fit your usecase better.Hey folks, just spent a few hours chasing down a very erratic error which turned out to be caused by a known bug: https://clojure.atlassian.net/browse/ASYNC-204 - would really appreciate if somebody could apply @cgrand's attached patch there, looks quite straight forward. I'm sure this would save other poor souls like me quite some nerves 🙂 Thanks 🙇
I will try to take a new look at it this week. I know I have looked at it in the past, don't remember why I did not apply it
might just have been the time to adequately review the proposal
@alexmiller Thanks a lot, that's great news 🙂
this code is both very dense, and in the path of everything using core.async so understanding the code, and the problem, and the proposed fix and considering other possible solutions can take hours
Heh, not as straight forward as it appears then, I guess!
and depending what the change is, I may also need to run it past Rich