Fork me on GitHub
#babashka
<
2023-08-04
>
borkdude09:08:04

🎉 7
viesti10:08:44

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 :D

borkdude10:08:37

we can add it but if you have found another way, we can delay

viesti10:08:28

yup, 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 🙂