Skip to content

Commit

Permalink
Add alive? function to expose java.lang.Process::isAlive (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzm committed Oct 7, 2022
1 parent d820dcd commit 5fb798d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/babashka/process.cljc
Expand Up @@ -592,3 +592,8 @@
(tokenize cmd))
cmd (into cmd args)]
(check (process prev cmd (merge default-shell-opts opts)))))

(defn alive?
"Returns `true` if the process is still running and false otherwise."
[p]
(.isAlive ^java.lang.Process (:proc p)))
7 changes: 7 additions & 0 deletions test/babashka/process_test.cljc
Expand Up @@ -285,6 +285,13 @@

(jdk9+)

(deftest alive-lives
(let [{:keys [in] :as res} (process '[cat])]
(is (true? (p/alive? res)))
(.close in)
@res
(is (false? (p/alive? res)))))

;;;; Windows tests
;;;; Run with clojure -M:test -i windows

Expand Down

0 comments on commit 5fb798d

Please sign in to comment.