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
impl Supervisor
Sourcepub fn builder() -> SupervisorBuilder
pub fn builder() -> SupervisorBuilder
Creates a new SupervisorBuilder for fluent task registration.
Sourcepub fn add(&mut self, proc: impl ManagedProc + 'static)
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.
Sourcepub async fn start(self) -> ProcResult
pub async fn start(self) -> ProcResult
Starts all registered processes and waits for completion or shutdown.
This method:
- Starts all processes concurrently
- Listens for SIGTERM or Ctrl+C signals
- On signal or error, shuts down all running processes in reverse order (LIFO)
- Returns the first error encountered or
Ok(())if all tasks complete successfully
Trait Implementations§
Source§impl Default for Supervisor
impl Default for Supervisor
Source§impl ManagedProc for Supervisor
impl ManagedProc for Supervisor
Source§fn run_proc(self: Box<Self>, shutdown: ShutdownSignal) -> ManagedFuture
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§
impl Freeze for Supervisor
impl !RefUnwindSafe for Supervisor
impl Send for Supervisor
impl Sync for Supervisor
impl Unpin for Supervisor
impl !UnwindSafe for Supervisor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more