This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-28
Channels
- # 100-days-of-code (10)
- # announcements (2)
- # architecture (16)
- # beginners (51)
- # bitcoin (3)
- # calva (1)
- # cider (6)
- # cljdoc (8)
- # cljs-dev (14)
- # cljsrn (4)
- # clojure (59)
- # clojure-italy (26)
- # clojure-losangeles (1)
- # clojure-nl (13)
- # clojure-spec (54)
- # clojure-uk (81)
- # clojurebridge (4)
- # clojurescript (20)
- # core-async (16)
- # cursive (39)
- # datomic (27)
- # emacs (12)
- # events (1)
- # figwheel-main (20)
- # fulcro (35)
- # funcool (1)
- # graphql (9)
- # hyperfiddle (10)
- # jobs (1)
- # jobs-discuss (7)
- # keechma (10)
- # lumo (22)
- # nrepl (18)
- # off-topic (28)
- # onyx (3)
- # pedestal (4)
- # re-frame (8)
- # reagent (8)
- # ring (4)
- # rum (3)
- # shadow-cljs (29)
- # testing (5)
I’m fairly new to Clojure and I’ve got a question regarding core.async channels. I’m using a http library which returns a channel - Now I want to do two http request at the same time and then “wait” for both to complete. How do I achieve such?
do you need to wait for both before the next step?
if so, you can call <!! on each channel to get the results
core.async has many options for asynchronous coordination, but if reading results in order as they are available works, it's probably the simplest option
so kinda like
(let [ch1 (http-request-1)
ch2 (http-request-2)
response1 (<!! ch1)
response2 (<!! ch2)]
(process-both-results response1 response2))
exactly
there's no way to do that directly, it might be easiest to use alts!! with a timeout-chan in that case
replace (<!! c) with (<!! (alts!! [c (timeout N)])), then you need to test if the result is the timeout or the http result
you're almost at the point of complexity where you might need a go block, but I don't think it's there yet