Fork me on GitHub
#core-async
<
2018-05-30
>
hiredman00:05:38

the one patch I managed to get in took something like 7 months, and I have a patch that hasn't seen any movement in over year, and I have some new patches that I just started the clock on

clark00:05:30

good plan

clark00:05:00

FWIW I have no idea whether what I’m doing is a decent approach, but Alex and I got into a twitter conversation about it here: https://twitter.com/clarkkampfe/status/995068142194962432

Alex Miller (Clojure team)00:05:01

I’m planning to do a pass on async this summer

Alex Miller (Clojure team)00:05:33

When depends on priority of other things but I have a bunch of stuff bookmarked

clark00:05:50

awesome, that’s good to know Alex. Thank you

Alex Miller (Clojure team)00:05:03

I’ve been on a consulting project for the last few months so I only have a few hrs a week right now but I’m expecting that to open up soon

clark00:05:54

cool, sounds good

souenzzo13:05:01

Hey. I'm doing something like

(let [chan (async/chan 100 xform)]
  (async/go-loop []
    (let [msg (async/<! chan)]
      (my-foo msg)
      (recur))
  (future (loop [pooling 0]
            (Thread/sleep 1000)
            ;; in the real world, it's a HTTP Request
            ;; that returns a "coll-of" msg
            (doseq [msg (range 10)]
              (async/>!! chan [pooling msg]))
            (recur (inc pooling)))))
In this cenario, my-foo will be called in parallel? Can I control how many parallel my-foo will run? Or it will be handled smartly as in golang?

noisesmith15:05:55

If my-foo is only in one go block it will have a maximum of 1 call running. You can start go blocks in a loop, or use something designed for parallel processing like pipeline, pipeline-async or pipeline-blocking

noisesmith15:05:19

Also, I understand this is a minimal example, but in real code you want to nil check your chan operation result and not call your function or recur if it's nil

👍 4
noisesmith15:05:11

(that is, bail if msg is nil)

mpenet15:05:59

No magic here. It works the same way as in golang

hiredman15:05:56

you can't put to a timeout channel

Logan Powell15:05:31

I'm not doing that at (let [ch (timeout 5000)])?

hiredman15:05:36

timeout returns channels that close after the given number of milliseconds, and it may return the same channel more than once (the channels are shared)

hiredman15:05:46

(>! ch ...)

hiredman15:05:58

you are not allowed to do that

Logan Powell15:05:37

I pulled this example from David Nolen, just retooling it a bit for node: http://swannodette.github.io/2013/07/12/communicating-sequential-processes

hiredman15:05:14

you replaced a real channel (chan) with (timeout) which doesn't do what you think it does

Logan Powell15:05:28

hmm... help me out here

Logan Powell15:05:42

I thought timeout returned a chan

hiredman15:05:48

you cannot put on to the channel returned by (timeout ...)

hiredman15:05:17

it does return a channel, but that channel is only there to signal you when the given number of milliseconds has elapsed

hiredman15:05:24

and it signals that by closing

hiredman15:05:45

you do not actually convey values over it

hiredman15:05:37

if you read further in that blog post you linked you can see them being used

Logan Powell15:05:10

so, I should (let [ch (chan (timeout 500))]...?

Logan Powell15:05:00

ok, i'm sorry if this is obvious. I'm new 😇

Logan Powell15:05:12

Let me get back to it then...

clark18:05:17

@loganpowell can you elaborate a bit on what you’re trying to achieve?

clark18:05:30

not super obvious to me from reading the code 😄

noisesmith18:05:09

I think it's based on one of dnolen's demos, just showing what core.async does