From 976cdf20cec31fc624af0b55246dc7600157ccd0 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 19 Oct 2024 14:00:05 +0200 Subject: [PATCH] concurrently --- src/babashka/process.cljc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/babashka/process.cljc b/src/babashka/process.cljc index af2e227..ff5ab30 100644 --- a/src/babashka/process.cljc +++ b/src/babashka/process.cljc @@ -724,3 +724,20 @@ :clj (when (contains? (loaded-libs) 'clojure.pprint) ;; pprint was already loaded, e.g. by nREPL (require '[babashka.process.pprint]))) + +(defn concurrently + ([commands] (concurrently nil commands)) + ([_opts commands] + (let [counter (atom -1) + proc-fn (fn [command] + (let [id (swap! counter inc)] + (prn "command" command) + (apply process + {:out-line-fn (fn [line] + (println (format "[%s]" id) line)) + :err-line-fn (fn [line] + (println (format "[%s]" id) line))} + command))) + procs (map proc-fn commands)] + (doseq [p procs] + (check p)))))