core-async

GGfpc 2021-05-14T21:00:52.160400Z

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

2021-05-14T21:18:34.161100Z

I would checkout the docstring for merge

2021-05-14T21:21:43.161900Z

you may want async/into

GGfpc 2021-05-14T22:00:19.162400Z

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 K 2021-05-14T22:17:27.163300Z

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