This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-28
Channels
- # announcements (11)
- # aws (30)
- # beginners (98)
- # calva (11)
- # cider (42)
- # clj-kondo (4)
- # cljdoc (1)
- # cljsrn (5)
- # clojure (132)
- # clojure-europe (4)
- # clojure-ireland (1)
- # clojure-italy (35)
- # clojure-japan (2)
- # clojure-nl (5)
- # clojure-spec (5)
- # clojure-uk (24)
- # clojurescript (71)
- # clojutre (1)
- # core-async (6)
- # cursive (9)
- # data-science (4)
- # datascript (3)
- # datomic (78)
- # duct (16)
- # emacs (14)
- # events (2)
- # fulcro (141)
- # graalvm (5)
- # hoplon (14)
- # hyperfiddle (2)
- # jobs-discuss (14)
- # joker (8)
- # luminus (2)
- # off-topic (7)
- # om (1)
- # pathom (4)
- # pedestal (7)
- # planck (2)
- # quil (1)
- # re-frame (14)
- # reagent (2)
- # reitit (14)
- # robots (1)
- # shadow-cljs (20)
- # spacemacs (25)
- # specter (1)
- # sql (122)
- # tools-deps (63)
- # unrepl (2)
- # yada (34)
yeah that's a good point, the order isn't defined with a/merge
, so it wouldn't be strictly ordered by arrival time if you e.g. waited a few seconds to take from the merged channel of typical web service calls
👍 4
Really interesting. In my case, as long as a have the fastest 4, I don’t care about the order within those 4.
One thing I wonder is, if for some reason service is not available, how would you do a timeout to ensure this doesn’t block forever?
merge takes channels so you could just add four (a/timeout your-preferred-delay)
or if doing my original way make each request alt on the actual response or a timeout channel
🙌 4
right, something like that:
(defn random-get [response-ch n]
(a/go
(let [wait (rand 4000)
res (a/alt! (a/timeout wait) wait
(a/timeout 1000) :skipped)]
(a/>! response-ch [n res]))))
(let [results-chan (a/chan 3 (take 4))]
(a/go
(dotimes [n 10]
(random-get results-chan n)))
(prn (repeatedly 4 #(a/<!! results-chan))))