Shutdown hooks docs

This commit is contained in:
Michiel Borkent 2020-04-08 21:18:56 +02:00
parent 110f6d7644
commit 2a1ad4e84f

View file

@ -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)