Fork me on GitHub
#core-async
<
2019-12-21
>
erwinrooijakkers15:12:57

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)))

erwinrooijakkers15:12:11

This returns [nil nil nil]

erwinrooijakkers15:12:20

Is the code wrong or is there nothing on the out channel?

dpsutton16:12:39

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

erwinrooijakkers16:12:17

Thanks. The new time window is fine. n amount of values will arrive and then stop

dpsutton16:12:11

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]

dpsutton16:12:18

it seems to work for me.

erwinrooijakkers17:12:53

I see, hmm thanks