Fork me on GitHub
#core-async
<
2019-03-29
>
dangercoder07:03:33

The main difference between Golang and Clojures Core-Async is that in Golang you do not have to care about "Blocking"?

dangercoder07:03:01

or would that be sorted using the async/thread-macro? i am trying to find some good reading material on this topic

danboykis12:03:23

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

danboykis12:03:41

core.async doesn't have a scheduler so having blocking IO is a bad idea, you risk dead locking core.async's threadpool

bortexz14:03:44

@U0CME35FV thanks for the gotraining link, it has some specifics for coroutine and channel designs and also other generic software design ideas, liked it 👍

👍 4
dangercoder14:03:39

I really liked it as well, thank you @U0CME35FV! 🙂

idiomancy23:03:19

so, I have this really common problem in core.async and have yet to figure out what the "correct" answer is

idiomancy23:03:54

basically, I need to go from channel of channels to channel of values

idiomancy23:03:03

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

hiredman23:03:22

continue, but my guess is you need to switch a map somewhere for pipeline or pipeline async

hiredman23:03:33

yeah, use pipeline

idiomancy23:03:44

at what point? supposing I have a channel where each value is a list of ten urls

hiredman23:03:46

depending, maybe merge

idiomancy23:03:36

ideally, ultimately, I want a channel where each value is the result of the get call

hiredman23:03:11

(pipeline-blocking 8 output-chan (map fetch) (onto-chan list-of-lists-of-urls))

idiomancy23:03:59

hmm.. so

(pipeline-blocking 8 output-chan (map (partial map fetch) input-chan)
is my situation.

idiomancy23:03:23

and then I still have a channel where each value is a list of channels

hiredman23:03:25

(comp cat (map fetch))

idiomancy23:03:03

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?

idiomancy23:03:29

if thats the case I guess I could just (pipeline-blocking 8 output-chan cat (onto-chan [(chan) (chan) (chan)]) right?

idiomancy23:03:00

well, to be more specific..

idiomancy23:03:03

(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?

idiomancy23:03:58

yeah, I still cant get this to work in any way

idiomancy23:03:47

im really not sure how pipeline helps me here, actually

idiomancy23:03:09

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