This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-04
Channels
- # architecture (5)
- # aws (11)
- # aws-lambda (1)
- # beginners (108)
- # boot (11)
- # cider (37)
- # clara (19)
- # cljsrn (72)
- # clojure (170)
- # clojure-austin (2)
- # clojure-dev (1)
- # clojure-dusseldorf (2)
- # clojure-italy (1)
- # clojure-spec (41)
- # clojure-uk (24)
- # clojurescript (113)
- # component (2)
- # core-async (29)
- # cursive (9)
- # data-science (5)
- # datomic (72)
- # docs (23)
- # duct (61)
- # editors (1)
- # emacs (1)
- # events (5)
- # fulcro (77)
- # graphql (2)
- # hoplon (4)
- # jobs (3)
- # jobs-discuss (16)
- # leiningen (5)
- # off-topic (94)
- # onyx (37)
- # precept (5)
- # re-frame (17)
- # reagent (11)
- # shadow-cljs (18)
- # spacemacs (107)
- # specter (3)
- # unrepl (64)
- # yada (1)
Hi, I have simple question. I’m loading some stuff from a file via a rest api. It’s all working and now I want to parallelize the process. I don’t really care about return values, etc in the program as errors are being logged to a file
so i’ve gone from something like (doseq [foo bar] (call-api foo))
to (doseq [foo bar] (go (call-api foo)))
The concern i have is that I’m doing this over multiple collections, and while it works fine for a given doseq/collection, the next doseq
shouldn’t start until the last one has completed. Not sure of the best way to make this happen
that's not what go is for
putting IO in go blocks is a good way to grind everything to a halt
(in the core.async world at least)
well, the io is problematic, but core.async is largely about communication, passing values around
there are good abstractions for managing parallel execution in the claypoole library
which uses FixedThreadPool as hiredman links iirc
if you find you do want to use values also there's some stuff in the core.reducers library I've inteded to try but I can't vouch for any of it
ah ok yeah Ive used that stuff before, was wondering if there was anything ‘clojury’ lol
claypoole is more clojury
but the nice thing with using a thread pool from clj is clojure functions are callable / runnable
so you don't need to use interop for that part at least
I would have expected this snippet to produce "true\nclosed\nfalse", but actually it remains true for the last line.
(let [continue? (async/to-chan (repeat true))]
(async/go
(println (async/<! continue?))
(async/close! continue?)
(println "closed")
(println (async/<! continue?))))
a closed channel doesn't return nil until all data buffered is consumed
I don't know how to-chan decides how much it buffers, clearly it's not unbuffered
with some experimentation you might figure out the buffer size (32, a common chunk size, would be a decent first guess)
Looks like it's 100: https://github.com/clojure/core.async/blob/2afc2dc5102f60713135ffca6fab993fb35809f0/src/main/clojure/clojure/core/async.clj#L646
cool, there we go