Skip to main content

Supervisor

Struct Supervisor 

Source
pub struct Supervisor<H> {
    pub events: Vec<Event>,
    pub interpreters_built: usize,
    /* private fields */
}

Fields§

§events: Vec<Event>§interpreters_built: usize

Interpreters constructed — one per spawn plus one per restart. Reported so the cost of per-process isolation is visible rather than hidden.

Implementations§

Source§

impl<H: 'static> Supervisor<H>

Source

pub fn new(strategy: Strategy, max_restarts: usize) -> Self

Source

pub fn spawn<F>(&mut self, chunk: Arc<Chunk>, budget: Budget, build: F) -> Pid
where F: Fn() -> Interpreter<H> + Send + Sync + 'static,

Add a child. Order matters for Strategy::RestForOne.

build constructs this process’s interpreter, and is called again on every restart. It is a factory rather than a value because a restart must produce a fresh environment: handing over one pre-built interpreter would mean a crashed process restarts into the globals that killed it.

Prefer forking to a closure that builds from scratch. A factory calling interpreter_hostless() evaluates the whole Lisp standard library on every spawn and every restart — ~945µs each, for an identical result — and a supervision tree under a crash loop pays it repeatedly. forking gives the same guarantee (a restart gets a clean private frame, and cannot write the prototype’s globals) for ~29µs.

Source

pub fn state_of(&self, pid: Pid) -> Option<&ProcState>

Source

pub fn proc_binds(&self, pid: Pid, name: &str) -> Option<bool>

Does this process’s own environment bind name?

Exposed because “a restart discards the environment” is otherwise untestable: a counter proves a rebuild was requested, not that the old bindings are gone. Also useful when debugging a supervision tree.

Source

pub fn restarts_of(&self, pid: Pid) -> Option<usize>

Source

pub fn has_work(&self, host: &H) -> bool
where H: Readiness,

Is anything still runnable? Is there anything to run right now?

A blocked process counts only if the host says it is ready. A blocked process with nothing pending is not work — it is a deadlock, and Supervisor::round reports it.

Source

pub fn deadlocked(&self, host: &H) -> Vec<Pid>
where H: Readiness,

Processes parked with nothing to wake them.

Source

pub fn round(&mut self, host: &mut H)
where H: Readiness,

Run one scheduling round: give every runnable process one quantum, then apply the restart strategy to anything that exited abnormally.

Round-robin, so a long-running child cannot starve a short one — that is preemption’s contribution, and it holds without any child cooperating.

Source

pub fn run_to_quiescence(&mut self, host: &mut H, max_rounds: usize) -> usize
where H: Readiness,

Drive rounds until nothing is runnable, or max_rounds elapse.

The bound is a test-and-operator safety net, not a semantic: a supervision tree that cannot settle should say so rather than spin.

Auto Trait Implementations§

§

impl<H> !RefUnwindSafe for Supervisor<H>

§

impl<H> !UnwindSafe for Supervisor<H>

§

impl<H> Freeze for Supervisor<H>

§

impl<H> Send for Supervisor<H>

§

impl<H> Sync for Supervisor<H>

§

impl<H> Unpin for Supervisor<H>

§

impl<H> UnsafeUnpin for Supervisor<H>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.