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§
- Actor
Config - Startup and behavioral configuration for a child actor, controlling parameters such as mailbox capacity, dispatch priority, and initialization arguments.
- Child
Spec - Specification for a supervised child actor.
- Degradation
Controller - Graceful degradation controller that wraps a
ResourceMonitorand makes admission-control decisions. - FnResource
Monitor - A resource monitor that reports
Elevatedwhen a closure returnstrueandCriticalwhen a second closure returnstrue. - Static
Resource Monitor - A static resource monitor that always reports the same pressure level.
- Supervised
Child - A child actor being supervised.
- Supervisor
- A supervisor that manages child actors.
- Supervisor
Handle - Thread-safe wrapper for supervisor operations.
- Supervisor
Stats - Statistics about a supervisor’s children.
- Supervisor
Tree - Hierarchical supervisor tree structure.
- Supervisor
Tree Stats - Statistics for the entire supervisor tree.
Enums§
- Child
State - State of a supervised child.
- Degradation
Decision - Result of a graceful degradation decision.
- Escalation
Action - Action to take when max restarts are exceeded.
- Exit
Reason - Why an actor terminated.
- Pressure
Level - Resource pressure level reported by a
ResourceMonitor. - Restart
Policy - Restart policy for a supervised child.
- Supervision
Strategy - How a supervisor should handle child failures.
- Supervisor
Error - Error type for supervisor operations.
Traits§
- Resource
Monitor - Trait for monitoring system resource pressure.