This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-19
Channels
- # arachne (1)
- # beginners (108)
- # boot (50)
- # cljs-dev (7)
- # clojure (76)
- # clojure-ireland (1)
- # clojure-romania (1)
- # clojure-russia (7)
- # clojure-spec (33)
- # clojure-taiwan (1)
- # clojure-uk (36)
- # clojurescript (46)
- # core-async (13)
- # datomic (146)
- # defnpodcast (1)
- # editors (1)
- # garden (2)
- # hoplon (1)
- # jobs (1)
- # lumo (7)
- # off-topic (21)
- # om (9)
- # pedestal (1)
- # re-frame (25)
- # reagent (5)
- # specter (2)
- # testing (3)
- # unrepl (3)
- # untangled (9)
- # vim (1)
if you have them in a sequence, doseq works
+user=> (time (>/<!! (>/go (doseq [t (doall (repeatedly 10 #(>/thread (Thread/sleep 1000))))] (>/<! t)))))
"Elapsed time: 1006.401197 msecs"
nil
without the doall, it would have taken 10 seconds instead of ~1
:user=> (time (>/<!! (>/go (doseq [t (repeatedly 10 #(>/thread (Thread/sleep 1000)))] (>/<! t)))))
"Elapsed time: 10012.202001 msecs"
nil
repeatedly is lazy, so each thread is not created until it is accessed
this may or may not apply to your threads - just wanted to make sure to show that aspect
(time
(>/<!!
(>/go
(doseq [t (dotimes [_ 10] #(>/thread (Thread/sleep 1000)))]
(>/<! t)))))
t will be a single nil
you need something that actually returns the threads, dotimes will not - it returns nil