[][src]Struct replicante_util_upkeep::Upkeep

pub struct Upkeep { /* fields omitted */ }

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

  1. Request all registered threads to shutdown.
  2. 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

let mut up = Upkeep::new();
up.on_shutdown(|| println!("Bye :wave:"));
up.wait();

Implementations

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]

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

impl Default for Upkeep[src]

impl Drop for Upkeep[src]

Auto Trait Implementations

impl !RefUnwindSafe for Upkeep

impl !Send for Upkeep

impl !Sync for Upkeep

impl Unpin for Upkeep

impl !UnwindSafe for Upkeep

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,