This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-23
Channels
- # announcements (29)
- # babashka (6)
- # beginners (55)
- # biff (4)
- # clj-kondo (5)
- # clojure (162)
- # clojure-austin (2)
- # clojure-europe (38)
- # clojure-nl (1)
- # clojure-norway (9)
- # clojure-sweden (2)
- # clojure-uk (10)
- # clojuredesign-podcast (5)
- # clojurescript (7)
- # conjure (8)
- # core-async (4)
- # cursive (34)
- # datahike (13)
- # datomic (9)
- # fulcro (5)
- # holy-lambda (2)
- # honeysql (1)
- # hugsql (3)
- # hyperfiddle (22)
- # jobs (5)
- # london-clojurians (1)
- # malli (2)
- # matrix (3)
- # off-topic (32)
- # pedestal (26)
- # polylith (18)
- # reitit (5)
- # releases (1)
- # ring (29)
Is mult
/`tap` the correct way to "keep" a value from a core.async operation so that it can be used by multiple go-blocks?
The workflow I am thinking of looks something like this:
(let [fetch-result (do-work-that-returns-chan x y)
action-1 (go (-> fetch-result
(<!)
(do-work-1)))
action-2 (go (-> fetch-result
(<!)
(do-work-2))
])
where the actions can be async. Of course, I could put all the action inside one go block, but then I'd have to put together things that I would like to be able to test separately, and it just doesn't seem ideal/composable.in this situation I'd lean towards something like this instead:
(go
(let [result (<! (do-work-that-returns-chan x y))
action-1 (go (-> result (do-work-1)))
action-2 (go (-> result (do-work-2)))]
))
alternatively you could use a promise-chan
(let [fetch-result-prom (a/pipe (do-work-that-returns-chan x y) (a/promise-chan))
action-1 (go (-> fetch-result-prom
(<!)
(do-work-1)))
action-2 (go (-> fetch-result-prom
(<!)
(do-work-2))
)]
)
> Of course, I could put all the action inside one go block, but then I'd have to put together things that I would like to be able to test separately, and it just doesn't seem ideal/composable. Imo the ideal is to have pure functions, test those, then wrap them all where they need to "come together"