pub struct SupervisedThread { /* private fields */ }Expand description
A supervised OS thread that owns its join handle and a HealthFlag. The worker
closure is the loop body; it receives the shutdown flag so it can exit promptly
and return SupervisedOutcome::Shutdown.
Implementations§
Source§impl SupervisedThread
impl SupervisedThread
Sourcepub fn spawn<F>(config: SupervisorConfig, worker: F) -> Self
pub fn spawn<F>(config: SupervisorConfig, worker: F) -> Self
Spawn a supervised thread. On a caught panic (under an unwind profile) or a
SupervisedOutcome::Restart, the worker body is re-entered with capped
backoff, reusing the same owned resources it captured. If the thread cannot be
spawned at all, the flag is tripped straight to Failed so no surface reads
green off a worker that never started.
Sourcepub fn health(&self) -> HealthFlag
pub fn health(&self) -> HealthFlag
A cloneable handle to this thread’s health.
Sourcepub fn shutdown(self) -> HealthLevel
pub fn shutdown(self) -> HealthLevel
Signal shutdown and join the worker. Returns the terminal health level.
Sourcepub fn join(self) -> HealthLevel
pub fn join(self) -> HealthLevel
Join after the worker reaches its own terminal condition without setting the shutdown flag. Use when another owned resource, such as a disconnected command channel, tells the worker to drain and exit.