[−][src]Struct replicante_util_upkeep::Upkeep
Block the calling thread until shutdown is requested.
Shutdown is requested when:
- The process receives SIGINT.
- A registered thread panics.
- A required thread exists (optional threads are allowed to exit gracefully).
Shutdown Flow
- Request all registered threads to shutdown.
- Execute all on_shutdown callbacks. 3 Wait for all registered threads to exit.
Threads and handlers are iterated on in registration order.
Signal Handling
When a process is sent SIGINT the shutdown flow begins. The process is allowed to take as long as it wants to shutdown.
If a second SIGINT is received while the process is shutting down it will instead exit immediately.
Example
# fn main() {
let mut up = Upkeep::new();
up.on_shutdown(|| println!("Bye :wave:"));
up.wait();
# }
Methods
impl Upkeep
[src]
pub fn new() -> Upkeep
[src]
pub fn keepalive(&mut self) -> bool
[src]
Block the calling thread waiting for the process to shutdown.
Returns
This method returns true
if the process shuts down cleanly.
pub fn on_shutdown<F>(&mut self, callback: F) where
F: Fn() + 'static,
[src]
F: Fn() + 'static,
Register a callback to be executed when a shutdown request is received.
pub fn register_signal(&mut self) -> Result<(), Error>
[src]
Register signal handers for SIGINT and SIGTERM.
pub fn register_thread<T: Send + 'static>(&mut self, thread: Thread<T>)
[src]
Register a Thread
for shutdown.
Threads are politely asked to stop work and then joined. Threads MUST join for the process to exit correctly.
If a Thread
registered with this function panics or exits
the shutdown procedure for all other threads begins.
pub fn register_thread_optional<T: Send + 'static>(&mut self, thread: Thread<T>)
[src]
Similar to Upkeep::register_thread
but clean exists do not shutdown the process.
pub fn set_logger(&mut self, logger: Logger)
[src]
Set the logger to be used by the Upkeep
instance.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Erased for T
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self