Fork me on GitHub
#core-async
<
2017-12-01
>
macalimlim17:12:10

Hi Im having trouble with this piece of code to work as I expected, could somebody help?

macalimlim17:12:34

(go-loop []
  (let [ch (async/take 100 external-channel)
         _ (async/close! ch)
         ps (<! (async/into [] ch))]
        (println "dispatch!! " ps))
  (recur))

macalimlim17:12:09

i taking 100 items from an xternal channel then put them into a vector

macalimlim17:12:28

then Ill take that vector off from that channel

macalimlim17:12:12

why is it looping forever even ch is empty? If I understood it right, <! should park I guess...

hiredman17:12:48

because the recur is unconditional

hiredman17:12:56

<! returns nil from a closed channel

hiredman17:12:21

sorry, nope I misread which channel is being closed

hiredman17:12:29

async/take returns at most N items, so if external-channel is closed, it will just return a closed channel, so nothing stops the loop from looping

macalimlim17:12:40

uhhhm external channel never closes

hiredman17:12:04

what is being printed?

macalimlim17:12:26

dispatch!! []

hiredman17:12:33

yeah, external-channel is closed

macalimlim17:12:47

thanks, Ill see what I could do...

hiredman17:12:54

also, I think async/take automatically closes the channel it returns, so you don't need to close ch