Skip to content

Commit e0e1179

Browse files
committed
Running the :shutdown hook as soon as the child process ends.
1 parent b781ec8 commit e0e1179

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/babashka/process.cljc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,11 @@
422422
(.thenRun (fn []
423423
;; To avoid a memory leak remove the hook when the process ends:
424424
(-> (Runtime/getRuntime)
425-
(.removeShutdownHook hook))))))))
425+
(.removeShutdownHook hook))
426+
;; But run the shutdown hook to ensure that cleanup
427+
;; tasks are executed:
428+
(.start hook)
429+
))))))
426430
(when exit-fn
427431
(if-before-jdk8
428432
(throw (ex-info "The `:exit-fn` option is not support on JDK 8 and lower." res))
@@ -479,7 +483,8 @@
479483
- `:cmd` - a vector of the tokens of the command to be executed (e.g. `[\"ls\" \"foo\"]`)
480484
- `:shutdown`: shutdown hook, defaults to `nil`. Takes process
481485
map. Typically used with `destroy` or `destroy-tree` to ensure long
482-
running processes are cleaned up on shutdown.
486+
running processes are cleaned up on shutdown. The shutdown hook is
487+
executed as soon as the child process ends.
483488
- `:exit-fn`: a function which is executed upon exit. Receives process map as argument. Only supported in JDK11+."
484489
{:arglists '([opts? & args])}
485490
[& args]

0 commit comments

Comments
 (0)