Supervisor

Struct Supervisor 

Source
pub struct Supervisor { /* private fields */ }
Expand description

Manages the lifecycle of multiple async workers with coordinated, ordered shutdown.

Supervisor runs all registered processes concurrently and handles graceful shutdown when receiving SIGTERM or Ctrl+C. Tasks are shutdown in reverse order of their initial registration (LIFO), allowing dependent tasks to stop their dependencies. This mimics the Patterns of process management hierarchy and dependency familiar in the OTP Erlang runtime.

§Example

use super_visor::Supervisor;

// Using the builder pattern
Supervisor::builder()
    .add_proc(server)
    .add_proc(worker)
    .build()
    .start()
    .await?;

// Or using direct construction
let mut supervisor = Supervisor::new();
supervisor.add(server);
supervisor.add(worker);
supervisor.start().await?;

Implementations§

Source§

impl Supervisor

Source

pub fn new() -> Self

Creates a new empty supervisor.

Source

pub fn builder() -> SupervisorBuilder

Creates a new SupervisorBuilder for fluent task registration.

Source

pub fn add(&mut self, proc: impl ManagedProc + 'static)

Adds a task to the supervisor

Tasks are started in the order they are added and shutdown in the reverse order.

Source

pub async fn start(self) -> ProcResult

Starts all registered processes and waits for completion or shutdown.

This method:

  1. Starts all processes concurrently
  2. Listens for SIGTERM or Ctrl+C signals
  3. On signal or error, shuts down all running processes in reverse order (LIFO)
  4. Returns the first error encountered or Ok(()) if all tasks complete successfully

Trait Implementations§

Source§

impl Default for Supervisor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl ManagedProc for Supervisor

Source§

fn run_proc(self: Box<Self>, shutdown: ShutdownSignal) -> ManagedFuture

Starts the process and returns a future that completes when the work is complete or runs indefinitely in a continual loop. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.