Better names

This commit is contained in:
Michiel Borkent 2020-08-01 20:00:27 +02:00
parent 04d30983be
commit 5a02faeb1f
2 changed files with 9 additions and 6 deletions

View file

@ -243,7 +243,7 @@
"LICENSE")) "LICENSE"))
(testing "bb is able to kill subprocesses created by ProcessBuilder" (testing "bb is able to kill subprocesses created by ProcessBuilder"
(when test-utils/native? (when test-utils/native?
(let [output (test-utils/bb nil (io/file "test" "babashka" "scripts" "child.bb")) (let [output (test-utils/bb nil (io/file "test" "babashka" "scripts" "kill_child_processes.bb"))
parsed (edn/read-string (format "[%s]" output))] parsed (edn/read-string (format "[%s]" output))]
(is (every? number? parsed)) (is (every? number? parsed))
(is (= 3 (count parsed))))))) (is (= 3 (count parsed)))))))

View file

@ -2,10 +2,13 @@
(set! *warn-on-reflection* true) (set! *warn-on-reflection* true)
(defn handles [^java.lang.ProcessHandle x] (defn child-process-handles [^java.lang.ProcessHandle x]
(distinct (cons x (mapcat handles (iterator-seq (.iterator (.descendants x))))))) (distinct
(cons x
(mapcat child-process-handles
(iterator-seq (.iterator (.descendants x)))))))
(defn run [& args] (defn start-spawning [& args]
(let [depth (or (System/getenv "DEPTH") "0") (let [depth (or (System/getenv "DEPTH") "0")
depth (Integer/parseInt depth)] depth (Integer/parseInt depth)]
(when-not (= 4 depth) (when-not (= 4 depth)
@ -20,7 +23,7 @@
(run! (fn [^java.lang.ProcessHandle handle] (run! (fn [^java.lang.ProcessHandle handle]
(do (prn (.pid handle)) (do (prn (.pid handle))
(.destroy handle))) (.destroy handle)))
(handles (.toHandle proc)))) (child-process-handles (.toHandle proc))))
(Thread/sleep 100000000)))))) (Thread/sleep 100000000))))))
(run "./bb" *file*) (start-spawning "./bb" *file*)