core-async

dehli 2019-02-14T00:39:11.018900Z

yep! i've already switched my nodejs project to using them and they're working perfectly 🎉

caleb.macdonaldblack 2019-02-14T01:18:23.019800Z

I watched Rich Hickey's talk "maybe not" and I love the idea of s/select

Jan K 2019-02-14T16:16:26.020500Z

I wonder why there's go-loop but not thread-loop shorthand in core.async

2019-02-14T18:23:58.021100Z

I think it's because go has to do tricky body rewrites, and go-loop can reduce that complexity compared to using loop

Jan K 2019-02-14T18:29:59.022400Z

go-loop just expands to (go (loop ...)), I don't see how that could help rewrites https://github.com/clojure/core.async/blob/master/src/main/clojure/clojure/core/async.clj#L458-L461

2019-02-14T18:36:18.023Z

because you shouldn't be looping in threads 🙂

2019-02-14T18:37:02.023800Z

a loop is usually going to wait on a timeout or a channel, both of which should be things you do in go loops,

2019-02-14T18:37:29.024700Z

and just do (async/<! (async/thread ...)) for io

Jan K 2019-02-14T18:49:02.030600Z

That's interesting and makes sense. But if I'm going to do IO for every input message, is it efficient to wrap every IO op in a thread, rather than the whole loop?

Jan K 2019-02-14T18:50:31.031300Z

It seems core.async is pooling and reusing the threads so I guess it might be OK

2019-02-14T18:57:23.031800Z

use (<! (thread (blocking-op))) inside go-loop

2019-02-14T18:57:45.032200Z

the pool is small and easy to exhaust / congest

2019-02-14T18:58:56.033600Z

I think which is best is kind of a thorny question, but it is clearly the design core.async pushes you towards

2019-02-14T19:00:10.034600Z

oh - did you mean the core.async/thread threads? yes those are pooled too, and I think the usage of thread to do one blocking op, letting you park on the result in the thread's channel, is the intended pattern

Jan K 2019-02-14T19:03:42.036200Z

Yes that's what I meant. Thanks for the ideas 🙂 I am reconsidering loops in my components now.

2019-02-14T20:40:31.037500Z

> because you shouldn’t be looping in threads 🙂 I’ve recently done this and now I dubious if what I did was right.

(dotimes [_ n]
    (async/thread
      (loop []
        (if-some [url (async/<!! ch)]
          (let [...]
            (do-work)
            (recur id))
          (log/info ::close)))))