This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-04
Channels
- # announcements (37)
- # babashka (4)
- # beginners (85)
- # calva (12)
- # chlorine-clover (4)
- # cider (20)
- # cljdoc (6)
- # clojure (37)
- # clojure-europe (44)
- # clojure-norway (46)
- # clojurescript (47)
- # conjure (1)
- # cursive (44)
- # datomic (23)
- # docs (2)
- # hyperfiddle (66)
- # introduce-yourself (4)
- # malli (16)
- # off-topic (7)
- # pathom (6)
- # portal (20)
- # re-frame (4)
- # releases (1)
- # shadow-cljs (56)
- # squint (1)
- # xtdb (9)
I was trying to do a scatter-gather thing (like spawning a bunch of futures, and waiting for all to complete before exiting) and noticed that java.util.concurrent.CountDownLatch doesn't seem to be available
0% bb
Babashka v1.3.182 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (java.util.concurrent.CountDownLatch. 1)
clojure.lang.ExceptionInfo: Unable to resolve classname: java.util.concurrent.CountDownLatch [at <repl>:2:1]
anyway, while writing this, realized that there are other options to do this since for example java.util.concurrent.Executors is available, but wrote this message anyway :Dyup, carrying on with something like this:
...
pool (java.util.concurrent.Executors/newFixedThreadPool (count clients))
reporter (java.util.concurrent.Executors/newFixedThreadPool 1)]
(doseq [client clients]
(.submit pool (fn []
;; Here do some long-running thing for a client
(.submit reporter (fn []
;; Then submit the result of the work for reporting
(println the-result))))))
(.shutdown pool)
(.awaitTermination pool 60 java.util.concurrent.TimeUnit/SECONDS)
(.shutdown reporter))}}}
...
and now remembering that babashka supported virtual threads even I think, so even that could be an option 🙂