Skip to main content

ctrl_c

Function ctrl_c 

Source
pub fn ctrl_c() -> impl FnOnce() + Send + 'static
Expand description

Returns a closure that blocks until Ctrl+C is received.

Multiple calls to this function are supported - each returns a closure that will be notified when Ctrl+C is pressed. This allows multiple actors to react to the same signal.

The signal handler is registered on the first call. Subsequent calls simply add new subscribers to the broadcast list.

§Example

// Both actors will be notified on Ctrl+C
send_message_on(actor1.clone(), rt::ctrl_c(), Msg::Shutdown);
send_message_on(actor2.clone(), rt::ctrl_c(), Msg::Shutdown);