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]
it seems to work for me.
I see, hmm thanks