Crates.io | simple_on_shutdown |
lib.rs | simple_on_shutdown |
version | 1.0.0 |
source | src |
created_at | 2020-12-01 22:10:09.168404 |
updated_at | 2021-05-19 19:11:14.482732 |
description | This crate consists of a convenient macro to specify on shutdown callbacks (=code that should run when your program exits (grafecully)). It's super simple and stripped-down. |
homepage | https://github.com/phip1611/simple_on_shutdown |
repository | https://github.com/phip1611/simple_on_shutdown |
max_upload_size | |
id | 318698 |
size | 62,122 |
This crate consists of a convenient macro to specify on shutdown callbacks called on_shutdown!
. It takes code that
should be executed when your program exits (gracefully). See https://docs.rs/simple_on_shutdown for more info.
Useful with "runtimes you do not have control over", like for example actix-web framework doesn't let you specify shutdown callbacks by yourself. In such cases my macro may be a better option.
use simple_on_shutdown::on_shutdown;
fn main() {
// macro can take: direct expression
on_shutdown!(println!("shut down with success"));
// closure expression
on_shutdown!(|| println!("shut down with success"));
// move closure expression
on_shutdown!(move || println!("shut down with success"));
// block
on_shutdown!({ println!("shut down with success") });
// identifier
let identifier = || println!("shut down with success");
on_shutdown!(identifier);
}
See "examples/"-dir in repository!.
CTRL+C / SIGINT / SIGTERM
SIGINT/SIGTERM
(and other signals) properly to allow a gracefully "non-regular"
shutdown (Actix web framework does this for example)
CTRL+C
will immediately shut down your appexample/src/bin/simple_example_ctrl_c_signal
for
more details.