Function gix::interrupt::init_handler

source ·
pub fn init_handler(
    grace_count: usize,
    interrupt: impl Fn() + Send + Sync + Clone + 'static
) -> Result<Deregister>
Available on crate feature interrupt only.
Expand description

Initialize a signal handler to listen to SIGINT and SIGTERM and trigger our trigger() that way. Also trigger interrupt() which promises to never use a Mutex, allocate or deallocate, or do anything else that’s blocking. Use grace_count to determine how often the termination signal can be received before it’s terminal, e.g. 1 would only terminate the application the second time the signal is received. Note that only the grace_count and interrupt of the first call are effective, all others will be ignored.

Use the returned Deregister type to explicitly deregister hooks, or to do so automatically.

Note

It will abort the process on second press and won’t inform the user about this behaviour either as we are unable to do so without deadlocking even when trying to write to stderr directly.