Fork me on GitHub
#core-async
<
2021-05-14
>
GGfpc21:05:52

Hello! Very beginner core.async question. Shouldn't this code return the result of processing all go blocks asynchronously? When I run it in the REPL it only returns the result of processing one of the blocks at random

(async/<!!
    (async/merge
      (map #(go (let [channel (async/chan)]
                  (fetch_meo_data % channel)
                  (let [result (async/<! channel)]
                    (async/close! channel)
                    result)))
           tv_channels)))

hiredman21:05:34

I would checkout the docstring for merge

hiredman21:05:43

you may want async/into

GGfpc22:05:19

Thanks for the tip! Turns out I needed both. Merge joins all the channels and into collects them

(async/<!! (async/into '() (async/merge
                               (map
                                 #(go (let
                                        [channel (async/chan)
                                         result (do
                                                  (fetch_meo_data % channel)
                                                  (handle-meo-response (async/<! channel)))]
                                        (async/close! channel)
                                        result))
                                 tv_channels))))

Jan K22:05:27

I think (<!! (async/map list <seq of go blocks>)) would be even easier