This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-21
Channels
- # adventofcode (20)
- # babashka (118)
- # beginners (170)
- # calva (1)
- # clojure (102)
- # clojure-europe (1)
- # clojure-nl (13)
- # clojure-uk (5)
- # clojuredesign-podcast (19)
- # code-reviews (10)
- # core-async (9)
- # cursive (7)
- # datomic (8)
- # fulcro (3)
- # malli (5)
- # mount (1)
- # off-topic (19)
- # overtone (1)
- # reagent (2)
- # reitit (2)
- # spacemacs (2)
- # sql (4)
- # tools-deps (5)
I try to read all values from a channel that arive in a second:
(loop [outputs []]
(let [[v p] (alts!! [out (timeout 1000)])]
(if v
(recur (conj outputs v))
outputs)))
This returns [nil nil nil]
Is the code wrong or is there nothing on the out
channel?
just off the cuff, you need the timout outside the loop. otherwise you get a new one-second window each time you get a value
Thanks. The new time window is fine. n amount of values will arrive and then stop
scratch.random> (let [out (doto (a/chan 5)
(a/>!! :value)
(a/>!! :value)
(a/>!! :value))]
(loop [outputs []]
(let [[v p] (a/alts!! [out (a/timeout 1000)])]
(if v
(recur (conj outputs v))
outputs))))
[:value :value :value]
I see, hmm thanks