From 2a1ad4e84fe69a8da2c556eeab9459ba0cc2f530 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Wed, 8 Apr 2020 21:18:56 +0200 Subject: [PATCH] Shutdown hooks docs --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index da8d8fcd..fec578d4 100644 --- a/README.md +++ b/README.md @@ -769,6 +769,17 @@ This can be useful for talking to Docker: :RepoTags) ;;=> ["borkdude/babashka:latest"] ``` +## Shutdown hook + +Adding a shutdown hook allows you to execute some code before the script exits. + +``` clojure +$ bb -e '(-> (Runtime/getRuntime) (.addShutdownHook (Thread. #(println "bye"))))' +bye +``` + +This also works when the script is interrupted with ctrl-c. + ## Bencode Babashka comes with the [nrepl/bencode](https://github.com/nrepl/bencode)