Skip to main content

Module supervisor

Module supervisor 

Source
Expand description

Erlang-style supervisor trees for hierarchical actor supervision.

This module implements the supervisor pattern from Erlang/OTP, providing fault-tolerant actor management with automatic restart policies and hierarchical supervision trees.

§Overview

Supervisors manage child actors with configurable restart strategies:

  • One-for-one: Restart only the failed child
  • One-for-all: Restart all children when one fails
  • Rest-for-one: Restart failed child and those started after it
  • Simple one-for-one: No restart, just acknowledge failure

§Example

ⓘ
use actor_kit::supervisor::{
    SupervisorTree, SupervisionStrategy, ChildSpec, RestartPolicy,
};
use std::time::Duration;

// Create a supervisor tree with one-for-one strategy
let mut tree = SupervisorTree::new(
    SupervisionStrategy::one_for_one(5, Duration::from_secs(60))
);

// Start a child actor under the root supervisor
let child_id = tree.start_child_under(
    tree.root(),
    ChildSpec {
        name: "worker-1".into(),
        actor_config: Default::default(),
        restart_policy: RestartPolicy::Permanent,
        shutdown_timeout: Duration::from_secs(30),
        significant: false,
    },
)?;

Structs§

ActorConfig
Startup and behavioral configuration for a child actor, controlling parameters such as mailbox capacity, dispatch priority, and initialization arguments.
ChildSpec
Specification for a supervised child actor.
DegradationController
Graceful degradation controller that wraps a ResourceMonitor and makes admission-control decisions.
FnResourceMonitor
A resource monitor that reports Elevated when a closure returns true and Critical when a second closure returns true.
StaticResourceMonitor
A static resource monitor that always reports the same pressure level.
SupervisedChild
A child actor being supervised.
Supervisor
A supervisor that manages child actors.
SupervisorHandle
Thread-safe wrapper for supervisor operations.
SupervisorStats
Statistics about a supervisor’s children.
SupervisorTree
Hierarchical supervisor tree structure.
SupervisorTreeStats
Statistics for the entire supervisor tree.

Enums§

ChildState
State of a supervised child.
DegradationDecision
Result of a graceful degradation decision.
EscalationAction
Action to take when max restarts are exceeded.
ExitReason
Why an actor terminated.
PressureLevel
Resource pressure level reported by a ResourceMonitor.
RestartPolicy
Restart policy for a supervised child.
SupervisionStrategy
How a supervisor should handle child failures.
SupervisorError
Error type for supervisor operations.

Traits§

ResourceMonitor
Trait for monitoring system resource pressure.