[][src]Function wintrap::trap

pub fn trap<RT: Sized>(
    signals: &'static [Signal],
    handler: impl Fn(Signal) + Send + Sync + 'static,
    body: impl FnOnce() -> RT
) -> Result<RT, Error>

Associates one or more Signals to an callback function to be executed in a dedicated thread while body is executing. A caveat of its usage is that only one thread is ever able to trap signals throughout the entire execution of your program. You are free to nest traps freely, however, only the innermost signal handlers will be executed.

Arguments

  • signals - A list of signals to trap during the execution of body.

  • handler - The handler to execute whenever a signal is trapped. These signals will be trapped and handled in the order that they are received in a dedicated thread. The handler will override the default behavior of the signal, in which most cases, is to end the process.

  • body - The code to execute while the trap is active. The return value will be used as the Ok value of the result of the trap call.