Skip to main content

Supervisor

Trait Supervisor 

Source
pub trait Supervisor {
    type Error: Debug;

    // Required method
    fn on_child_failure(
        &mut self,
        child_id: &str,
        error: &Self::Error,
    ) -> SupervisorAction;
}
Expand description

A trait for supervised machine groups (structured concurrency).

Supervisors monitor a set of child machines and react when any child enters a failure state. The supervisor decides whether to restart the child, escalate the error, or ignore it by returning a SupervisorAction.

§Examples

use gust_runtime::prelude::*;

struct MyGroup;

impl Supervisor for MyGroup {
    type Error = String;

    fn on_child_failure(&mut self, child_id: &str, error: &String) -> SupervisorAction {
        eprintln!("Child {child_id} failed: {error}");
        SupervisorAction::Restart
    }
}

Required Associated Types§

Source

type Error: Debug

The error type reported by child machines.

Required Methods§

Source

fn on_child_failure( &mut self, child_id: &str, error: &Self::Error, ) -> SupervisorAction

Called when a child machine enters a failure state.

The supervisor inspects the child_id and error and returns a SupervisorAction that determines how the runtime should respond.

Implementors§