Shutdown Hook
The on shutdown block is Zolo's equivalent of a process destructor: it runs
when the program exits normally, when process.exit is called explicitly, or
when the process receives a signal that terminates execution. The reason
parameter (optional) receives a string describing the cause — "normal" for a
clean exit.
The hook fires after process.exit(0) — the print("unreachable") is never
executed. Run in your local environment to see the message order.
// Verifies `on shutdown` fires when `process.exit` is called explicitly.
use std::process
on shutdown reason {
print("shutdown reason: {reason}")
}
print("before exit")
process.exit(0)
print("unreachable")
Requires the Zolo CLI/host — open in the playground or run locally.
The block is registered in the order it appears in the source, but executed in reverse order (LIFO) when multiple hooks exist — the one closest to the end of the file runs first, allowing inner layers to clean up before outer ones.
Challenge
Remove the reason argument from on shutdown and verify the block still
compiles and fires. Then add a second on shutdown before the first and
observe the execution order.
See also