The main difference between Golang and Clojures Core-Async is that in Golang you do not have to care about "Blocking"?
or would that be sorted using the async/thread-macro? i am trying to find some good reading material on this topic
Yes, golang has a scheduler that detects blocking sys calls and spins up a new physical thread: https://github.com/ardanlabs/gotraining/tree/master/topics/go/concurrency/goroutines
core.async doesn't have a scheduler so having blocking IO is a bad idea, you risk dead locking core.async's threadpool
@danboykis thanks for the gotraining link, it has some specifics for coroutine and channel designs and also other generic software design ideas, liked it 👍
I really liked it as well, thank you @danboykis! 🙂
so, I have this really common problem in core.async and have yet to figure out what the "correct" answer is
basically, I need to go from channel of channels to channel of values
so, I have a channel that contains a list of values, and I perform an async call on each of those values, and the async call returns a channel. Now I have a channel that has a list of channels
continue, but my guess is you need to switch a map somewhere for pipeline or pipeline async
yeah, use pipeline
oh really?
at what point? supposing I have a channel where each value is a list of ten urls
depending, maybe merge
ideally, ultimately, I want a channel where each value is the result of the get call
(pipeline-blocking 8 output-chan (map fetch) (onto-chan list-of-lists-of-urls))
hmm.. so
(pipeline-blocking 8 output-chan (map (partial map fetch) input-chan)
is my situation.and then I still have a channel where each value is a list of channels
(comp cat (map fetch))
oh, so that cat is going to emit values one at a time? that wouldn't say, wait for all the fetches to produce a value?
if thats the case I guess I could just
(pipeline-blocking 8 output-chan cat (onto-chan [(chan) (chan) (chan)])
right?
well, to be more specific..
(pipeline-blocking 8 output-chan cat
(to-chan [(go 1) (go (<! (timeout 1000)) 2) (go (<! (timeout 4000)) 3)]))
so in this case, would output-chan require 0 seconds or 4 seconds to emit its first value?yeah, I still cant get this to work in any way
im really not sure how pipeline helps me here, actually
well, having no "correct" way of doing things, here's what I have been doing.
(defn chain! [in!]
(let [out! (a/chan)]
(a/go-loop
[next! (a/<! in!)]
(if next!
(do
(<! (go (loop [subval (a/<! next!)]
(when subval (a/>! out! subval)
(recur (a/<! next!))))))
(recur (a/<! in!)))
(a/close! out!)))
out!))